1

I'm looking for a way to launch the default weather application via an Intent. I tried to use the package name for Android's default weather app like indicated in this question.

Other than that I looked on Android developer website for some clues but couldn't find anything.

Community
  • 1
  • 1
Chris911
  • 4,131
  • 1
  • 23
  • 33

3 Answers3

1

You should first get the package of that android app which you can find it in the AndroidManifest.xml file then write this code where you want to launch that weather application

PackageManager pm = getPackageManager();
String packageName = "com.your.packagename";
Intent launchIntent =  pm.getLaunchIntentForPackage(packageName);
startActivity(launchIntent);

And make sure the application is installed

Abhijit Chakra
  • 3,201
  • 37
  • 66
1

I needed to do it in an Android Wear app, and I managed to do it using this answer : https://stackoverflow.com/a/12511404/7006743

Here is my code to launch the default Android Wear weather app :

ComponentName cn = new ComponentName("com.google.android.wearable.app", "com.google.android.clockwork.home.search.apps.weather.WeatherActivity");
try {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    intent.setComponent(cn);
    startActivity(intent);
} catch(ActivityNotFoundException e){
    Toast.makeText(getApplicationContext(), "activity not found", Toast.LENGTH_LONG).show();
}

To find the component name, just start the desired app and check what happens in LogCat.

Community
  • 1
  • 1
0

After june 2022 :

    localIntent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.apps.search.weather.WeatherExportedActivity");
                    startActivity(localIntent);
Croid
  • 111
  • 5