<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test01"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test01.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity01"
android:label="@string/activity01"
android:icon="@drawable/authentication_name_n">
<intent-filter >
<action android:name="cxd.test.demo"/>
</intent-filter>
</activity>
<activity android:name=".Activity02"
android:label="@string/activity02"
android:icon="@drawable/box_tj_h">
<intent-filter >
<action android:name="cxd.test.demo"/>
</intent-filter>
</activity>
<activity android:name=".Activity03"
android:label="@string/activity03"
android:icon="@drawable/box_tj">
<intent-filter >
<action android:name="cxd.test.demo"/>
</intent-filter>
</activity>
</application>
</manifest>
这个是在manifest.xml配置文件中每个activity中配置了一个intent的行动,然后在MainActivity中
public class MainActivity extends ListActivity {
private PackageManager mPackageManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPackageManager = getPackageManager();
List<ResolveInfo> activities = mPackageManager.queryIntentActivities(
makeDemoActivityIntent(), PackageManager.GET_META_DATA);
getListView().setAdapter(
new ActivityListAdapter(this, activities, mPackageManager));
}
protected Intent makeDemoActivityIntent() {
Intent intent = new Intent(Constants.DEMO_ACTION);
return intent;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
ActivityInfo resolveInfo = ((ResolveInfo) l.getItemAtPosition(position)).activityInfo;
Intent intent = new Intent();
intent.setComponent(new ComponentName(resolveInfo.packageName,
resolveInfo.name));
startActivity(intent);
}
}
这里的
Intent intent = new Intent(Constants.DEMO_ACTION);参数就是
<action android:name="cxd.test.demo"/>里的参数
public class ActivityListAdapter extends BaseAdapter { private List<ResolveInfo> mData; private LayoutInflater mInflater; private PackageManager mPackageManager; public ActivityListAdapter(Context context, List<ResolveInfo> data, PackageManager packagetManager) { mData = data; mInflater = LayoutInflater.from(context); mPackageManager = packagetManager; } @Override public int getCount() { return mData.size(); } @Override public ResolveInfo getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ResolveInfo resolveInfo = getItem(position); if (null == convertView) { convertView = mInflater.inflate( android.R.layout.simple_list_item_1, parent, false); } ((TextView) convertView) .setText(resolveInfo.loadLabel(mPackageManager)); ((TextView) convertView).setCompoundDrawables( resolveInfo.loadIcon(mPackageManager), null, null, null); return convertView; } }
在ListActivity中点击每一个item然后就可以进入到activity中去,如果要做中文匹配的话在res文件里面新建values-zh-rCN.xml配置文件中新建string.xml文件,写中文版的