启动Android的天气应用通过intent [英] Launching Android Weather App Via Intent

查看:159
本文介绍了启动Android的天气应用通过intent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个从我的Andr​​oid应用程序启动股票的天气应用程序
意图,但我不断收到一个部队密切运行时错误,并LogCat中
给我什么。在code我试图用它来实现这一目标是:

 公共无效startWeatherActivity(){
   意向意图=新意图(android.intent.action.MAIN);
   intent.setComponent(ComponentName.unflattenFromString(org.anddev.android.weatherforecast /
        org.anddev.android.weatherforecast.WeatherForecast));
   intent.addCategory(android.intent.category.LAUNCHER);
   startActivity(意向);
}


解决方案

尝试从getLaunchIntentFromPackage让你的意图:
<一href=\"http://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage%28java.lang.String%29\"相对=nofollow>安卓DOC

只是作为一个评论,您应该使用明确的字符串常量Intent.ACTION_MAIN。

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); 
} 

解决方案

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.

这篇关于启动Android的天气应用通过intent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆