我尝试在ICS上以编程方式激活或停用Android Beam功能,但我找不到任何api。可能吗 ?
我会知道在启动推送操作之前是否启用了Android Beam功能。有可能吗?
答案 0 :(得分:2)
在手机的设置中,您可以启用和禁用Android Beam功能(无线网络 - >更多... - > Android Beam)。普通应用程序没有必要的权限来打开或关闭它(并且没有API)。但是,您可以使用new Intent(Settings.ACTION_WIRELESS_SETTINGS)
从应用中发送和转发Intent,直接打开此设置屏幕。
在Android 4.1 JB上,添加了一个新的API调用NfcAdapter.isNdefPushEnabled(),以检查Android Beam是否已打开或关闭。
BTW:即使禁用了Android Beam,只要打开NFC,您的设备仍然可以接收Beam消息。答案 1 :(得分:0)
您可以根据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();
}
}
(我现在将此代码放入公共领域,不需要许可条款或归属地)