Can someone tell me please why this gives me null on the variable intent
?
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);
}
}
i test this on a pixel 4 and i never do uninstall youtube. also, sidequest list the app and gives me the package com.google.android.youtube
For many (perhaps most) PackageManager
methods, on Android 11 and higher, you need to take into account package visibility rules and add a <queries>
element to your manifest to declare what third-party apps you are interest in discovering or analyzing.
Add below code in manifiest at below level hope it will work with you.
<manifest
<application
>
</application>
<queries>
<intent>
<action android:name="com.google.android.youtube.api.service.START"/>
</intent>
</queries>
</manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With