我正在使用Eclipse和Android SDK构建一个Android应用程序。我想在我的应用程序中实现一个近场通信P2P函数,当你将2部手机背靠背放置时,两者都会自动发送和接收字符串。这当然会在一个单独的活动中发生。我已经设法发送了一个自定义标记(字符串),但无法拦截它并在以后的应用程序代码中使用它。我该怎么做呢?
这就是我到目前为止所知道的:
public class MainActivity extends Activity {
public NfcAdapter mAdapter;
PendingIntent mPendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = NfcAdapter.getDefaultAdapter(this);
NdefRecord rec = NdefRecord.createUri("www.stackoverflow.com");
NdefMessage ndef = new NdefMessage(rec);
mAdapter.setNdefPushMessage(ndef, this);
}
我花了很多时间试图找到和理解拦截标签的解决方案。不成功。
谢谢你的帮助。
发布于 2015-05-12 19:08:04
onResume()
中的
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,new Intent(this,getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);nfcAdapter.enableForegroundDispatch(this,pendingIntent,null,null);
https://stackoverflow.com/questions/30186739
复制相似问题