gpt4 book ai didi

java - onNewintent() 执行时我的应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 18:15:43 28 4
gpt4 key购买 nike

我只是想创建一个同时实现指纹扫描和 NFC 读取的 Android 应用程序。在不同的时间都发挥着良好的作用。但如果我在指纹扫描仪打开时尝试扫描 NFC 卡,则会崩溃。NFC 卡正在读取,Android 设备将生成一个新的 Intent。此时将调用 onNewIntent() 方法。在 onNewIntent() 之后,控制将转到 onResume()。 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}

最佳答案

尝试一下我的工作代码。

首先将以下行添加到 onCreate()

mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

然后在您的调用 Activity 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);

然后将以下代码行添加到 onPause()

 if (mNfcAdapter != null)
mNfcAdapter.disableForegroundDispatch(this);

并在 list 中添加以下权限

<uses-permission android:name="android.permission.NFC" />

关于java - onNewintent() 执行时我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60373817/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com