Launching Android Weather App Via Intent

时光怂恿深爱的人放手 提交于 2019-12-23 02:32:26

问题


I want to launch the stock weather app from my android app via an intent, but I keep getting a force close runtime error, and LogCat gives me nothing. The code I am trying to use to achieve this is:

public void startWeatherActivity() { 
   Intent intent = new Intent("android.intent.action.MAIN"); 
   intent.setComponent(ComponentName.unflattenFromString("org.anddev.android.weatherforecast/
        org.anddev.android.weatherforecast.WeatherForecast")); 
   intent.addCategory("android.intent.category.LAUNCHER"); 
   startActivity(intent); 
} 

回答1:


Try to get your intent from getLaunchIntentFromPackage: android doc

just as a comment, you should use Intent.ACTION_MAIN instead of the explicit string constant.



来源:https://stackoverflow.com/questions/6748195/launching-android-weather-app-via-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!