当我尝试扫描二维码时,我的应用程序正在关闭。我之前没有使用 asynctask,它工作正常,我想我对 asynctask 的工作方式有问题,任何建议都会受到欢迎。下面是我的日志
03-26 12:19:16.797: E/AndroidRuntime(1104): FATAL EXCEPTION: Thread-101
03-26 12:19:16.797: E/AndroidRuntime(1104): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
03-26 12:19:16.797: E/AndroidRuntime(1104): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
03-26 12:19:16.797: E/AndroidRuntime(1104): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
03-26 12:19:16.797: E/AndroidRuntime(1104): at android.app.Activity.startActivityForResult(Activity.java:3370)
03-26 12:19:16.797: E/AndroidRuntime(1104): at android.app.Activity.startActivityForResult(Activity.java:3331)
03-26 12:19:16.797: E/AndroidRuntime(1104): at com.example.restaurantapp.MainActivity$InitTask$1.run(MainActivity.java:68)
03-26 12:19:16.797: E/AndroidRuntime(1104): at java.lang.Thread.run(Thread.java:856)
这是我的主要活动
public class MainActivity extends Activity {
Button btnScan;
TextView result1;
ImageView imgScan;
InitTask scan;
//@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//btnScan=(Button)findViewById(R.id.button1);
imgScan=(ImageView)findViewById(R.id.imageButton1);
imgScan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scan=new InitTask();
scan.execute();
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
result1=(TextView)findViewById(R.id.textView1);
String values = intent.getStringExtra("SCAN_RESULT");
//String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
result1.setText(values);
Toast.makeText(MainActivity.this,
"Scan Result:" + values, Toast.LENGTH_LONG)
.show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(MainActivity.this, "you cancelled scanning", Toast.LENGTH_LONG).show();
}
}
}
private class InitTask extends AsyncTask<Void,Void,Void>{
protected Void doInBackground(Void...unused){
new Thread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
}).start();
return null;
}
}
}
请帮忙,知道是什么原因造成的吗?谢谢你 :)