开发者

Android Intent (ActionNotFoundException)

i got the following problem: I am developing an app which requires the zxing-QR-Code reader to work properly. But how shall I know if it is installed? I found some code which should fix the problem but wont work, so i figured I might ask wehere I found this code:

/**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);
        开发者_如何学Ct.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); 
    }

So the actual problem is, that when i try to start the marketplace (via a yes button) the app just crashes!


Use the IntentIntegrator class supplied by ZXing to kick off your scans, and it will detect the missing Barcode Scanner application and will lead the user to download it. Or, examine the source code to IntentIntegrator and apply its techniques.


To look if the Scanner App is available, search it over the PacketManager.

PacketManager pm = this.getPacketManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;

The Intent in this example is:

Intent i = new Intent("com.google.zxing.client.android.SCAN");

To start the market if the App isn't available i would go it this way over the URI for the App. As i know Uri's with "market://*"-prefix will always redirect in the marketapp.

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.zxing.client.android"));
startActivity(i);

Hop this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜