Android Beam-以编程方式激活

Android Beam-以编程方式激活,android,nfc,android-beam,Android,Nfc,Android Beam,我尝试在ICS上以编程方式激活或停用Android Beam功能,但我找不到任何用于此的api。可能吗 在启动推送操作之前,我会知道是否启用了Android Beam功能。有可能吗?在手机的设置中,您可以启用和禁用Android Beam功能(无线网络->更多…->Android Beam)。普通应用程序没有打开或关闭此功能所需的权限(并且没有API)。但是,您可以使用new Intent(Settings.ACTION\u WIRELESS\u Settings)直接从应用程序发送并打开此设置

我尝试在ICS上以编程方式激活或停用Android Beam功能,但我找不到任何用于此的api。可能吗


在启动推送操作之前,我会知道是否启用了Android Beam功能。有可能吗?

在手机的设置中,您可以启用和禁用Android Beam功能(无线网络->更多…->Android Beam)。普通应用程序没有打开或关闭此功能所需的权限(并且没有API)。但是,您可以使用
new Intent(Settings.ACTION\u WIRELESS\u Settings)
直接从应用程序发送并打开此设置屏幕

在Android 4.1 JB上,添加了一个新的API调用,以检查Android Beam是打开还是关闭


顺便说一句:即使禁用了Android Beam,只要打开NFC,您的设备仍然能够接收Beam消息。

您可以根据Android版本和当前状态具体选择要显示的设置屏幕。我是这样做的:

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;

@TargetApi(14)
// aka Android 4.0 aka Ice Cream Sandwich
public class NfcNotEnabledActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Intent intent = new Intent();
        if (Build.VERSION.SDK_INT >= 16) {
            /*
             * ACTION_NFC_SETTINGS was added in 4.1 aka Jelly Bean MR1 as a
             * separate thing from ACTION_NFCSHARING_SETTINGS. It is now
             * possible to have NFC enabled, but not "Android Beam", which is
             * needed for NDEF. Therefore, we detect the current state of NFC,
             * and steer the user accordingly.
             */
            if (NfcAdapter.getDefaultAdapter(this).isEnabled())
                intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
            else
                intent.setAction(Settings.ACTION_NFC_SETTINGS);
        } else if (Build.VERSION.SDK_INT >= 14) {
            // this API was added in 4.0 aka Ice Cream Sandwich
            intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
        } else {
            // no NFC support, so nothing to do here
            finish();
            return;
        }
        startActivity(intent);
        finish();
    }
}
(我在此将此代码放入公共域,无需许可条款或属性)

使用
新意图(设置。操作\u NFCSHARING\u设置)
将用户带入Android Beam设置。NFC guy建议的,将带您进入NFC设置(这也很有用)。