本文介绍了通过意向Zxing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序使用斑马线库。我通过intent启动德zxing酒吧codescanner。但是,当用户没有安装吧codescanner。该应用程序停止工作。如何检查是否已安装了zxing酒吧codescanner?
In my application I use the zxing library. I start de zxing barcodescanner via intent. But when the user has no barcodescanner installed. The application stops working. How can I check if a zxing barcodescanner is already installed?
推荐答案
您可以使用下面的代码片段来检查是否安装了用户的设备上特定的应用程序
You can use following snippet to check if particular application is installed on user's device
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.facebook.android", 0 );
return true;
} catch( PackageManager.NameNotFoundException e ){
return false;
}
有关具体Zxing您将使用以下内容。
For Specific Zxing you will use following.
Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent1,
PackageManager.MATCH_DEFAULT_ONLY);
if(list.size() > 0)
// Zxing is available
else
// Zxing is not available
一旦你找到Zxing可可以称之为如下:
Once you find Zxing is available you can call it as follows
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
这篇关于通过意向Zxing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!