Android 中由应用程序A启动应用程序B的方法(两种):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*function one*/
Intent intent = new Intent();
intent.setClassName("org.cvpcs.android.sensordump","org.cvpcs.android.sensordump.AListSensors");
startActivity(intent);
/*function two*/
Intent intent = new Intent();
ComponentName cn = new ComponentName("org.cvpcs.android.sensordump","org.cvpcs.android.sensordump.AListSensors");
intent.setAction(Intent.ACTION_MAIN);
intent.setComponent(cn);
intent.putExtra("aaa","bbb");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
如何查看一个应用程序apk的包名和对应的类名:
1.手机运行应用
2.adb shell
3.dumpsys window | grep mCurrentFocus
4.得到如下结果
其中 包名就是 org.cvpcs.android.sensordump 类名就是 org.cvpcs.android.sensordump.AListSensors