Android的:改变NFC设置(开/关)编程 [英] Android: Changing NFC settings (on/off) programmatically

查看:1134
本文介绍了Android的:改变NFC设置(开/关)编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

解决方案

您无法将其开/关手动,但你可以发送用户的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());

这篇关于Android的:改变NFC设置(开/关)编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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