No Activity found to handle Intent action.VIEW when clicking email link

后端 未结 3 1299
情深已故
情深已故 2021-02-07 16:02

I got this new crash exception after the newest app update. It seems to not point anywhere. Would anyone be able to tell what the issue is? It looks like a possible email-forma

3条回答
  •  野性不改
    2021-02-07 16:37

    I ran into this problem as well, the thing is that when you define:

    android:autoLink="email"
    android:text="some@email.com"
    

    or any other type of autolink in a TextView, android handles everything for you.

    In the emulator email is not setup by default, so there is no app to handle the intent, and this makes your app crash if you click an autolinked email address. If you open the mail app and follow the instructions to set it up, then when you click the email address it will work.

    I don't know what you can do to work around this issue. I guess it might not be safe to assume the user has mail setup or at least one app capable of handling that intent. I also guess that the app shouldn't be crashing... I think this is an issue with android as in this case you have no way of handling the exception.

    If you look at the source of URLSpan (If autolink is set, TextView uses android.text.util.Linkify.addLinks(..) which creates instances of URLSpan to create links): http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.2_r1/android/text/style/URLSpan.java#URLSpan

    public void onClick(View widget) {
        Uri uri = Uri.parse(getURL());
        Context context = widget.getContext();
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(intent);
    }
    

    They could either handle the exception or use PackageManager to determine if the Intent would succeed before calling startActivity() (like they recommend: http://developer.android.com/training/basics/intents/sending.html#Verify) or use a chooser.

    Although the Android platform guarantees that certain intents will resolve to one of the built-in apps (such as the Phone, Email, or Calendar app), you should always include a verification step before invoking an intent.

    Caution: If you invoke an intent and there is no app available on the device that can handle the intent, your app will crash.

    So my question would be: is there any guarantee that an email intent will always resolve on a real device?

    ok... on the same section they also mention:

    Note: You should perform this check when your activity first starts in case you need to disable the feature that uses the intent before the user attempts to use it. If you know of a specific app that can handle the intent, you can also provide a link for the user to download the app (see how to link to your product on Google Play).

    One can always check if the intent resolves to any activity at the start of the application, set a flag and every time the layout containing such TextView is inflated we find it and disable auto link for email, etc. (and this is when I ponder killing an unicorn over coding that)

提交回复
热议问题