查找所有activity
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
/** 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");
}
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer