我得到了以下問題: 我正在開發一個應用程序,它需要zxing-QR-Code閱讀器正常工作。但是我怎麼知道它是否安裝? 我發現一些代碼,應該可以解決問題,但不會工作,所以我想我可能會問wehere我發現這個代碼:Android意圖(ActionNotFoundException)
/**someQC**/
public void function() {
if(!isIntentAvailable(this, "com.google.zxing.client.android.SCAN")) {
intentNotAvaiable("com.google.zxing.client.android"); //handle no intent
}
/**somemoreQC to deal with the intent**/
private void intentNotAvaiable(String intentName) {
setContentView(R.layout.intentnotavailable);
TextView t = new TextView(this);
t = (TextView)findViewById(R.id.aint_available);
t.setText(intentName + "unbekannt, weiterleitung\n zum AndroidApp Market Place?");
gotoMarketPlace = ("market://search?q=pub:" + intentName);
}
public void goToMarketPlace(View view) { //this is the Button handler
Intent promptInstall = new Intent(Intent.ACTION_SEARCH).setPackage("com.android.vending").putExtra("query", gotoMarketPlace);
startActivity(promptInstall);
}
所以實際的問題是,當我嘗試啓動市場(通過是的按鈕)該應用程序只是崩潰!
我現在試着去適應IntentIntegrator,我只是不想c&p,但是我完全被這個混淆了:'public static final Method PACKAGE_SETTER; static { Method temp; 嘗試temp = Intent.class.getMethod(「setPackage」,new Class [] {String.class}); (NoSuchMethodException nsme){ temp = null; } PACKAGE_SETTER = temp; }' – Sim
@Sim:'setPackage()'是在Android 2.1左右添加的。他們希望在可用的情況下使用該方法,但如果他們直接引用它,他們的代碼會在較早的Android設備上崩潰。反射是在保持向後兼容性的同時使用更新的Android功能的一種方式。 – CommonsWare
我現在成功地適應了,但即使我安裝了條碼掃描器,我仍然得到了Activity Invalid intent = new Intent(「com.google.zxing.client.android.SCAN」)。addCategory(Intent.CATEGORY_DEFAULT).putExtra ( 「SCAN_FORMATS」, 「QR_CODE_MODE」); activity.startActivityForResult(inte,42);' – Sim