[英]My app crashes when onNewintent() executes
I just want to create an android application that implements both Fingerprint scanning and NFC reading together.我只想创建一个同时实现指纹扫描和 NFC 读取的 android 应用程序。 It works well in at different times.
它适用于不同的时间。 But if I try to scan The NFC card when the fingerprint scanner is ON, it gets crashes.
但是如果我在指纹扫描仪开启时尝试扫描 NFC 卡,它会崩溃。 The NFC card is reading, a new intent will generated by the android device.The onNewIntent() method will invoke at that time.
NFC 卡正在读取,android 设备将生成一个新的意图。届时将调用 onNewIntent() 方法。 After this onNewIntent(), the control will goes to onResume().
在此 onNewIntent() 之后,控件将转到 onResume()。 Fingerprint scanning codes are added in onResume().When control goes here, the app get crashing.
在 onResume() 中添加指纹扫描码。当控制到这里时,应用程序会崩溃。
@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
initDevice();
if (mFingerprint != null) {
tvInfo.setText("");
mFingerprint.startIdentification();
}
WriteModeOn();
}
public void initDevice() {
new InitTask().execute();
}
public class InitTask extends AsyncTask<String, Integer, Boolean> {
ProgressDialog mypDialog;
@Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return mFingerprint.init();
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
mypDialog.dismiss();
if (!result) {
// Toast.makeText(Read_RFIDActivity.this, "fail",
// Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Read_RFIDActivity.this, "initialization success", Toast.LENGTH_SHORT).show();
}
tvInfo.setText("");
mFingerprint.startIdentification();
// start();
getEmpRealm();
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mypDialog = new ProgressDialog(Read_RFIDActivity.this);
mypDialog.setCanceledOnTouchOutside(false);
mypDialog = ProgressDialog.show(Read_RFIDActivity.this, "Scanner Initializing...", "Please wait...", true, false);
}
}
Logcat逻辑猫
2020-02-24 15:46:36.523 19339-19339/com.oges.timefingerprint.attendance V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@54870d
2020-02-24 15:46:36.523 19339-19339/com.oges.timefingerprint.attendance V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@631a6c2
2020-02-24 15:46:36.526 19339-19339/com.oges.timefingerprint.attendance V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@74e3010
2020-02-24 15:46:36.526 19339-19339/com.oges.timefingerprint.attendance V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@b4f8709
2020-02-24 15:46:36.537 19339-19339/com.oges.timefingerprint.attendance I/DeviceAPI_Fingerprint: startIdentify =>runing=true
2020-02-24 15:46:36.537 19339-19339/com.oges.timefingerprint.attendance I/DeviceAPI_Fingerprint: what==iENROLLL && enrollCallBack==null
2020-02-24 15:46:36.604 19339-19435/com.oges.timefingerprint.attendance I/DeviceAPI_Fingerprint: morphoIdentify() end
2020-02-24 15:46:36.605 19339-19435/com.oges.timefingerprint.attendance E/AndroidRuntime: FATAL EXCEPTION: Thread-50
Process: com.oges.timefingerprint.attendance, PID: 19339
java.lang.NullPointerException: Attempt to get length of null array
at java.lang.StringFactory.newStringFromChars(StringFactory.java:211)
at com.rscja.deviceapi.FingerprintWithMorpho.morphoIdentify(FingerprintWithMorpho.java:917)
at com.rscja.deviceapi.FingerprintWithMorpho.access$19(FingerprintWithMorpho.java:897)
at com.rscja.deviceapi.FingerprintWithMorpho$ThreadIdentification.getData(FingerprintWithMorpho.java:735)
at com.rscja.deviceapi.FingerprintWithMorpho$ThreadIdentification.run(FingerprintWithMorpho.java:724)
2020-02-24 15:46:36.610 19339-19339/com.oges.timefingerprint.attendance D/DeviceAPI: pre finger init
2020-02-24 15:46:36.611 19339-19339/com.oges.timefingerprint.attendance E/DeviceAPI_Fingerprint: free() err:-1
2020-02-24 15:46:36.611 19339-19339/com.oges.timefingerprint.attendance E/freeeeeeeeeee: ------In Free()........
2020-02-24 15:46:36.731 19339-19339/com.oges.timefingerprint.attendance V/AsyncHttpRH: Progress 13 from 13 (100%)
2020-02-24 15:46:36.732 19339-19339/com.oges.timefingerprint.attendance I/Server Request:: {"code":1}
try this my working code.试试这个我的工作代码。
first add below line into onCreate()首先将以下行添加到 onCreate()
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
then Add below line on your calling activity onResume() method然后在您的调用活动 onResume() 方法上添加以下行
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
IntentFilter[] nfcIntentFilter = new IntentFilter[]{techDetected, tagDetected, ndefDetected};
if (mNfcAdapter != null)
mNfcAdapter.enableForegroundDispatch(this, pendingIntent, nfcIntentFilter, null);
then add below line of code into onPause()然后将以下代码行添加到 onPause()
if (mNfcAdapter != null)
mNfcAdapter.disableForegroundDispatch(this);
and into manifest add below permission并在清单中添加以下权限
<uses-permission android:name="android.permission.NFC" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.