请问为什么这段代码会使变量
intent
的值为null?public class MainActivity extends AppCompatActivity {
private static String action = "com.google.android.youtube";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onResume() {
super.onResume();
this.launch();
}
public void launch() {
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(action);
System.out.println("debug: " + intent);
//startActivity(intent);
}
}
我在Pixel 4上测试,从未卸载YouTube应用程序。 另外,SideQuest列出了该应用程序并提供了包名com.google.android.youtube