package com.necsthz.android.demo;

 

import java.util.Collections;

import java.util.List;

 

import android.app.Activity;

import android.content.ComponentName;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

import android.text.InputType;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

 

public class AppFindActivity extends Activity {

private EditText mEdtInputKey;

private EditText mEdtStart;

private TextView mTxtFoundRst;

private String mStrInputKey;

private StringBuffer mStrFoundRst;

private List mAppsList;

/** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

 

        mEdtInputKey = (EditText) findViewById(R.id.edtKeywd);

        mEdtInputKey.getInputType();

        mEdtInputKey.setInputType(InputType.TYPE_NULL);

        mEdtStart = (EditText) findViewById(R.id.edtStart);

        mTxtFoundRst = (TextView) findViewById(R.id.txtFoundRst);

        Button btnGet = (Button) findViewById(R.id.btnGet);

        btnGet.setOnClickListener(new OnClickListener(){

@Override

public void onClick(View v) {

mStrInputKey = mEdtInputKey.getText().toString().trim();

mStrFoundRst = new StringBuffer();

seekAppActivities();

mTxtFoundRst.setText(mStrFoundRst);

}

        });

 

        Button btnStart = (Button) findViewById(R.id.btnStart);

        btnStart.setOnClickListener(new OnClickListener(){

@Override

public void onClick(View v) {

try {

if ((mAppsList != null) && (mAppsList.size() > 0)) {

int idStart = Integer.parseInt(mEdtStart.getText().toString().trim());

ResolveInfo info = mAppsList.get(idStart);

Intent intent = new Intent(Intent.ACTION_MAIN);;

intent.addCategory(Intent.CATEGORY_LAUNCHER);

       intent.setComponent(

        new ComponentName(

info.activityInfo.packageName,

info.activityInfo.name));

       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

       

AppFindActivity.this.startActivity(intent);

}

} catch (Exception e) {

e.printStackTrace();

}

}

        });

    }

    private void seekAppActivities() {

     PackageManager appManager = getPackageManager();

//     manager.getInstalledApplications(flags)

//     manager.getInstalledPackages(flags);

 

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

// mainIntent.addCategory(Intent.CATEGORY_DEFAULT);

 

mAppsList = appManager

.queryIntentActivities(mainIntent, 0);

Collections.sort(mAppsList,

new ResolveInfo.DisplayNameComparator(appManager));

 

addDisplayTxt("�u" + mAppsList.size() + "�v items is found:");

for (int i = 0; i < mAppsList.size(); i++) {

ResolveInfo info = mAppsList.get(i);

if (info.activityInfo.name.contains(mStrInputKey)) {

addDisplayTxt("index: " + i);

addDisplayTxt("Name: " + info.activityInfo.name);

addDisplayTxt("PkgName: " + info.activityInfo.packageName);

}

}

    }

 

private void addDisplayTxt(String str) {

mStrFoundRst.append(str + "/n");

System.out.println(str + "/n");

}

}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. kotlin 对话框_使用Kotlin的Android警报
  2. 【Android】ScrollView内动态添加图片间
  3. LocalBroadcastManager详解
  4. android 获取Service(服务)的运行状态
  5. Android(安卓)开发佳站3
  6. 超级简单的Google VR SDK播放VR视频
  7. Android(安卓)插件化分析(5)- 加载外部dex
  8. Android(安卓)ImageView部分圆图处理组件
  9. Android(安卓)NetworkImageView点击查看
  10. Android(安卓)3.0动画系统详解