Java 防止在读取NFC标记时应用程序暂停
我正在构建一个Android应用程序,它将使用库读取NFC标签 当我在应用程序中读取标签时,它会最小化,并由内置的Android标签阅读器处理。是否可以停止应用程序暂停,让它在文本视图中显示内容 注意:TagReaderActivity只是一个扩展 以下是我当前的代码:Java 防止在读取NFC标记时应用程序暂停,java,android,nfc,ndef,Java,Android,Nfc,Ndef,我正在构建一个Android应用程序,它将使用库读取NFC标签 当我在应用程序中读取标签时,它会最小化,并由内置的Android标签阅读器处理。是否可以停止应用程序暂停,让它在文本视图中显示内容 注意:TagReaderActivity只是一个扩展 以下是我当前的代码: import org.ndeftools.Message; import android.os.Bundle; import android.widget.LinearLayout; import android.widget
import org.ndeftools.Message;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.seaf.nfc.TagReaderActivity;
public class DemoNFCActivity extends TagReaderActivity {
protected LinearLayout linearLayout;
private static final String DEMO = DemoNFCActivity.class.getName();
protected TextView feature;
protected TextView state;
protected TextView data;
@Override
public void onCreate(Bundle savedInstanceState) {
this.setContentView(R.layout.layout_demo_nfc);
feature = (TextView) findViewById(R.id.textView1);
state = (TextView) findViewById(R.id.textView2);
data = (TextView) findViewById(R.id.textView3);
super.onCreate(savedInstanceState);
}
@Override
protected void readNdefMessage(Message message) {
// [INSERT SOLUTION HERE] :D
//
// if (data != null) {
//
// data.setText(message.toString());
// data.setBackgroundColor(getResources().getColor(R.color.green_light));
//
// }
}
@Override
protected void onNfcFeatureFound() {
super.onNfcFeatureFound();
if (feature != null) {
feature.setText(getString(R.string.nfc_feature_true));
feature.setBackgroundColor(getResources().getColor(R.color.green_light));
}
}
@Override
protected void onNfcFeatureNotFound() {
super.onNfcStateDisabled();
if (feature != null) {
feature.setText(getString(R.string.nfc_feature_false));
feature.setBackgroundColor(getResources().getColor(R.color.red_light));
}
}
@Override
protected void onNfcStateEnabled() {
super.onNfcStateEnabled();
if (state != null) {
state.setText(getString(R.string.nfc_state_true));
state.setBackgroundColor(getResources().getColor(R.color.green_light));
}
}
@Override
protected void onNfcStateDisabled() {
super.onNfcStateDisabled();
if (state != null) {
state.setText(getString(R.string.nfc_state_false));
state.setBackgroundColor(getResources().getColor(R.color.red_light));
}
}
}
您需要注册前台调度系统(如果您的应用程序仅限于Android 4.4+,则可以选择读卡器模式系统)。有关如何使用前台调度系统的更多信息,请参阅Android NFC
对于ndeftools库,
NfcDetectorActivity
应该执行(或适应)您想要的操作。NFC子系统首先调用onPause(),然后调用onNewIntent(),然后调用onResume()。您不需要解决这个问题,因为整个过程非常简短
这里的问题似乎是你的前台模式没有被激活。请参阅中的onCreate()方法,并注意对的调用
setDetecting(true);
这是因为您不一定要始终接受传入的NFC流量。您是否有定义NFC子系统调用的文档来源?我的搜寻毫无结果。