Intent.CATEGORY_APP_CALCULATOR:ActivityNotFoundException [英] Intent.CATEGORY_APP_CALCULATOR: ActivityNotFoundException

查看:29
本文介绍了Intent.CATEGORY_APP_CALCULATOR:ActivityNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android 应用程序中打开默认计算器应用程序.设备中安装了两个计算器:默认的 android 计算器和 Google计算器.

I'm trying to open the default calculator app in a android application. Two calculators are installed in device: default android calculator and Google Calculator.

Intent calc = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);

此代码抛出 ActivityNotFoundException 并在 logcat 中显示:

This code is throwing an ActivityNotFoundException and shows this in logcat:

system_process W/IntentResolver: resolveIntent failed: found match, but none with CATEGORY_DEFAULT

此代码具有相同的行为:

This code have the same behavior:

Intent calc = new Intent(Intent.ACTION_MAIN);
calc.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);

这是 Android 错误?如何打开应用选择器,让用户选择默认应用?

It's a Android bug? How to open the application chooser, to let user select the default app?

堆栈跟踪:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] sel=act=android.intent.action.MAIN cat=[android.intent.category.APP_CALCULATOR]} }
     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
     at android.app.Activity.startActivityForResult(Activity.java:3930)
     at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
     at android.app.Activity.startActivityForResult(Activity.java:3890)
     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
     at android.app.Activity.startActivity(Activity.java:4213)
     at android.app.Activity.startActivity(Activity.java:4181)
     at com.MyActivity.openCalc(MyActivity.java:202)
     at com.MyActivity.onOptionsItemSelected(MyActivity.java:191)
     at android.app.Activity.onMenuItemSelected(Activity.java:2914)
     at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
     at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
     at android.app.ActivityThread.main(ActivityThread.java:5461)

推荐答案

似乎文档指向的方式不起作用.尽管如此,此代码通常会打开默认的计算器应用程序.

It seems like the way, that documentation points to doesn't work. Nevertheless, this code will normally open default calculator app.

Intent intent = new Intent();
intent.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(intent);

这篇关于Intent.CATEGORY_APP_CALCULATOR:ActivityNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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