意图 android.settings.NFC_PAYMENT_SETTINGS 的 ActivityNotFoundException [英] ActivityNotFoundException for intent android.settings.NFC_PAYMENT_SETTINGS

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

问题描述

我正在尝试打开 NFC Tap & 上的设置带有这段代码的支付页面:

I'm trying to open settings on NFC Tap & Pay page with this piece of code:

startActivity(new Intent(Settings.ACTION_NFC_PAYMENT_SETTINGS));

在使用 Android 7.1.2 的 LG Nexus 5X 上进行测试时,我收到了此崩溃:

While testing on LG Nexus 5X with Android 7.1.2 I have received this crash:

android.content.ActivityNotFoundException:
 No Activity found to handle Intent { act=android.settings.NFC_PAYMENT_SETTINGS }
  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1809)
  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
  at android.app.Activity.startActivityForResult(Activity.java:4228)
  at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(SourceFile:50)
  at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:79)
  at android.app.Activity.startActivityForResult(Activity.java:4186)
  at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:859)
  at android.app.Activity.startActivity(Activity.java:4525)
  at android.app.Activity.startActivity(Activity.java:4493)
  at ...

嗯,这个崩溃可以通过 try-catch 轻松处理,但奇怪的是,当我手动打开这个 NFC 设置时,代码就像一个魅力 - 没有崩溃.为什么?有没有人对这种行为有解释?

Well, this crash can be handled easilly with try-catch but what is wierd, when I open this NFC settings manually, code works like a charm - no crash. Why? Does anyone have an explanation for this behavior?

在文档[1]中是这样写的:

In documentation[1] is written this:

在某些情况下,匹配的 Activity 可能不存在,因此请确保您防止这种情况发生.

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

他们的意思是否可能是您必须手动打开设置,然后才能正常工作"这样的句子?

Is it possible that they meant this sentence like "you have to open settings manually, then it works fine"?

[1] https://developer.android.com/参考/android/provider/Settings.html#ACTION_NFC_PAYMENT_SETTINGS

推荐答案

来自:https://developer.android.com/reference/android/provider/Settings.html#ACTION_NFC_PAYMENT_SETTINGS

在 API 级别 19 中添加

ACTION_NFC_PAYMENT_SETTINGS

added in API level 19

字符串 ACTION_NFC_PAYMENT_SETTINGS

String ACTION_NFC_PAYMENT_SETTINGS

活动动作:显示 NFC Tap &支付设置

Activity Action: Show NFC Tap & Pay settings

这会显示允许用户配置 Tap&Pay 设置的 UI.

This shows UI that allows the user to configure Tap&Pay settings.

在某些情况下,匹配的 Activity 可能不存在,因此请确保您对此加以防范.

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

输入:无

输出:无

常量值:android.settings.NFC_PAYMENT_SETTINGS"

Constant Value: "android.settings.NFC_PAYMENT_SETTINGS"

您的设备不支持或至少无法处理 ACTION_NFC_PAYMENT_SETTINGS.

ACTION_NFC_PAYMENT_SETTINGS is not supported by your device or can at least not be handled.

由于您的 minAPILevel 为 19,因此 android RT 应该支持该操作.但是,操作与 NFC 设置菜单(尽管菜单存在)之间的链接可能未建立或无法建立.

Since your minAPILevel is 19, the action should be supported by the android RT. However, it is possible, that the link between the action and the NFC settings-menu, ALTHOUGH the menu exists, is not or can not be established.

尝试使用 Settings.ACTION_NFC_SETTINGS 作为动作,看看它是否启动.如果是这样,我预计会出现实施问题.

Try to use Settings.ACTION_NFC_SETTINGS as the action and see if it starts. If so, I'd expect an implementation issue.

为了防止出现异常,我建议使用:

To guard against the exceptions, I'd recommend using:

PackageManager packageManager = getActivity().getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
    startActivity(<your intent>);
} else {
    Log.d(TAG, "No application available to handle requested action.");
}

参见:如何检查是否可以从某些活动中处理意图? 以供参考.

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

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