mBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String package_name = "com.debug.loggerui";
PackageManager packageManager = getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(package_name);
startActivity(intent);
}
如果这样使用,我在ud版本上运行没问题,然后我在user版本使用,就会报以下问题,但是看来看去好像是没获得上下文,加了之后也是没任何用的,依旧报以下问题,在网上看到,有让改配置文件,又让修改版本的,这些都没啥用
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1721)
at android.app.Activity.startActivityForResult(Activity.java:5320)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
at android.app.Activity.startActivityForResult(Activity.java:5278)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
at com.example.startota.MainActivity.startActivityForResult(MainActivity.java:48)
at android.app.Activity.startActivity(Activity.java:5664)
这样写才能解决解决该问题
mBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ComponentName componentName = new ComponentName("com.debug.loggerui", "com.debug.loggerui.MainActivity");
Intent intent = new Intent();
intent.setAction("com.intent.action.START_WIFI");
intent.setComponent(componentName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});