No Activity found to handle Intent

后端 未结 6 1322
攒了一身酷
攒了一身酷 2020-12-01 17:35

i am attempting to launch an intent to open a link to the android market.

android manifest portion looks like this:



        
相关标签:
6条回答
  • 2020-12-01 18:07

    Try adding

    <category android:name="android.intent.category.DEFAULT" />
    

    to the calling Activity.

    0 讨论(0)
  • 2020-12-01 18:12

    You are running this code on an Android environment that lacks the Google Play Store, such as an emulator, Kindle Fire, etc.

    If you are encountering this on an emulator, test this code path on a device that has the Play Store.

    If you are encountering this on some piece of hardware that lacks the Play Store, or if you are planning on distributing your app to devices that lack the Play Store, either handle the exception or use PackageManager and resolveActivity() to determine if your Intent will succeed before calling startActivity().

    if(intent.resolveActivity(getPackageManager()) != null)
        startActivityForResult(intent, 0);
    else
        ...
    
    0 讨论(0)
  • 2020-12-01 18:12

    Better solution would be to try to open uri in Google Play app, but if there is no such app (no Activity to handle this intent) - you can just try to open uri in browser like in this example:

    public static void rateApp(Context context) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())));
        } catch (android.content.ActivityNotFoundException anfe) {
            viewInBrowser(context, "https://play.google.com/store/apps/details?id=" + context.getPackageName());
        }
    }
    
    public static void viewInBrowser(Context context, String url) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        if (null != intent.resolveActivity(context.getPackageManager())) {
            context.startActivity(intent);
        }
    }
    
    0 讨论(0)
  • 2020-12-01 18:17

    I got the same error because I wrote:

    Linking.openURL('www.somewebsite.com');
    

    Changing the URL to http://somewebsite.com (or https://somewebsite.com, depending on the website You are targeting) fixed the problem :)

    0 讨论(0)
  • 2020-12-01 18:21

    You can use Intent.createChooser() method to safely launch the Intent. If no application exists that can handle your intent, a dialog will be displayed telling the user just that. If however Google Play Store is installed, the user can that choose to "open" the intent in Play Store.

    startActivity(Intent.createChooser(marketIntent, "dialogTitle"));
    
    0 讨论(0)
  • 2020-12-01 18:24
    private void OpenStoreIntent(){
            String url="";
            Intent storeintent=null;
            try {
                url = "market://details?id=com.myapp.packagename";
                storeintent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                storeintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                context.startActivity(storeintent);
            } catch ( final Exception e ) {
                url = "https://play.google.com/store/apps/details?id=com.myapp.packagename";
                storeintent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                storeintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                context.startActivity(storeintent);
            }
    
        }
    
    0 讨论(0)
提交回复
热议问题