Search code examples
javaandroidandroid-studioandroid-intentandroid-implicit-intent

How to Access Default Apps, having no application id?


I am learning Implicit Intents. I am making an app to cover most of the implicit intent concepts, ScreenShot of this app is here.

enter image description here

In this App, I want to get access to device default Weather and Radio applications. But the problem is these two apps don't even have Application id. I have searched a lot to get the Application id of these two default apps in my device Oppo. And what if I run this application on another phone that has different application id so, how to solve this problem?

Both of these two applications are here:

enter image description here


Solution

  • You can't open these apps like a browser with an implicit intent. Different manufacturers use different weather and radio apps. So, the only solution is to launch the app using the package name. To find out the package of the app you can use ADB or any package viewer app. For example, next one https://play.google.com/store/apps/details?id=com.csdroid.pkg&hl=uk

    And then open the app with the next code.

    public void openApp(Context context, String packageName) {
    PackageManager packageManager = context.getPackageManager();
    Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
    
    if (launchIntent != null) {
        context.startActivity(launchIntent);
    } else {
        Toast.makeText(context, "Package not found", Toast.LENGTH_SHORT).show();
    }}