应该做什么:使用已整合的ZXING
扫描条形码并将条形码保存到应用的SQLite database
。
首先,我尝试扫描条形码并使用Toast-Message
在屏幕上显示它到目前为止它工作得很好。
之后,我添加了将barcode
插入数据库的功能。从那以后我收到了以下错误:
12-29 11:58:00.363 28012-28012/com.factory.future.ap_manager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.factory.future.ap_manager, PID: 28012
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) }} to activity {com.factory.future.ap_manager/com.factory.future.ap_manager.MainActivity}: java.lang.IllegalArgumentException: Unknown URL content://com.factory.future.ap_manager/aps
at android.app.ActivityThread.deliverResults(ActivityThread.java:4520)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.IllegalArgumentException: Unknown URL content://com.factory.future.ap_manager/aps
at android.content.ContentResolver.insert(ContentResolver.java:1276)
at com.factory.future.ap_manager.MainActivity.addAP(MainActivity.java:116)
at com.factory.future.ap_manager.MainActivity.onActivityResult(MainActivity.java:95)
at android.app.Activity.dispatchActivityResult(Activity.java:7282)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4516)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
以下是处理扫描结果的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
addAP(result.getContents());
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private void addAP(String barcodeNumber) {
int codeLength = barcodeNumber.length();
barcodeNumber = barcodeNumber.substring(4,codeLength - 1);
int APID = Integer.parseInt(barcodeNumber);
//Toast.makeText(this, "Scanned: " + APID, Toast.LENGTH_LONG).show();
String title = "TestAP-" + barcodeNumber;
ContentValues values = new ContentValues();
values.put(APEntry.AP_ID, 13222);
values.put(APEntry.AP_TITLE, title);
Toast.makeText(this, APEntry.CONTENT_URI.toString(), Toast.LENGTH_LONG).show();
getContentResolver().insert(APEntry.CONTENT_URI, values);
}
我还尝试将Intent跳到ZXING
并直接调用addAP
方法中的onClick
函数。在那里得到以下错误:
java.lang.IllegalArgumentException: Unknown URL content://com.factory.future.ap_manager/aps
这是所有文件的链接: Link
答案 0 :(得分:0)
问题解决了!
CONTENT_URI本身也是正确的,但在AndroidManifest.xml
我写了android:authorities="com.future.factory.ap_manager"
而不是android:authorities="com.factory.future.ap_manager"
。
(在查看代码时错过了数百次)