Android的:改变NFC设置(开/关)编程Android、NFC

2023-09-13 23:40:57 作者:秋凉

我试图改变NFC设置(开/关)编程方式在Android 2.3.3。

在手机上,在无线和网络设置, 你可以选择设置你是否要使用NFC读取和交换标签与否。

所以,我想切换在我的应用此设置。 但我似乎无法找到一个API,用于这一点。

我在找一些code,它很可能是这样的:

  WifiManager无线=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(开/关);
 

解决方案 传谷歌移动支付AndroidPay将于9月16日上线

您无法将其开/关手动,但你可以发送用户的preferences如果是关闭

 如果(!nfcForegroundUtil.getNfc()。IsEnabled的())
    {
        Toast.makeText(getApplicationContext(),请激活NFC和preSS返回,返回给应用程序!,Toast.LENGTH_LONG).show();
        startActivity(新意图(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
    }
 

方法 getNfc()仅返回 nfcadapter

  

NFC = NfcAdapter.getDefaultAdapter(activity.getApplicationContext());

I trying to change NFC settings (on/off) programmatically on Android 2.3.3.

On the phone, under the "Wireless & network settings", you can choose to set whether you want to use NFC to read and exchange tags or not.

So I would like to toggle this setting in my application. But I can't seem to find an api for this.

I'm looking for some code that would probably look like this:

WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled( on/off );

解决方案

You can not turn it on/off manually but you can send the user to the preferences if it is off:

    if (!nfcForegroundUtil.getNfc().isEnabled())
    {
        Toast.makeText(getApplicationContext(), "Please activate NFC and press Back to return to the application!", Toast.LENGTH_LONG).show();
        startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
    }

Method getNfc() just returns the nfcadapter:

nfc = NfcAdapter.getDefaultAdapter(activity.getApplicationContext());