I want to open Google calendar app from my app. I have following code but it crashes:
if (Utils.isPackageInstalled(PACKAGENAME,getApplicationContext())) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse( "com.android.calendar"));
startActivity(intent);
}
LogCat:
04-30 09:14:29.156: E/AndroidRuntime(21225): FATAL EXCEPTION: main
04-30 09:14:29.156: E/AndroidRuntime(21225): Process: com.am, PID: 21225
04-30 09:14:29.156: E/AndroidRuntime(21225): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=com.android.calendar }
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Activity.startActivityForResult(Activity.java:3424)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Activity.startActivityForResult(Activity.java:3385)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Activity.startActivity(Activity.java:3627)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.Activity.startActivity(Activity.java:3595)
04-30 09:14:29.156: E/AndroidRuntime(21225): at com.amexbarcelo.activity.RootActiveTravel$4.onClick(RootActiveTravel.java:147)
04-30 09:14:29.156: E/AndroidRuntime(21225): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.os.Handler.dispatchMessage(Handler.java:102)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.os.Looper.loop(Looper.java:136)
04-30 09:14:29.156: E/AndroidRuntime(21225): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-30 09:14:29.156: E/AndroidRuntime(21225): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 09:14:29.156: E/AndroidRuntime(21225): at java.lang.reflect.Method.invoke(Method.java:515)
04-30 09:14:29.156: E/AndroidRuntime(21225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-30 09:14:29.156: E/AndroidRuntime(21225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-30 09:14:29.156: E/AndroidRuntime(21225): at dalvik.system.NativeStart.main(Native Method)
Its not advisable to use the package name for 3rd party application in intent for launching. You must specify the Action and URI and let the system find the best app to handle the request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.