开发者

Android browsable intent fails on gmail links, but works with default mail client

I have set up intent filters to handle certain email links with my app. This works well in Android's basic mail program. I click the link, I am prompted whether to open it using the browser or my app, and after selecting my app it is handled correctly. The same is not true for using the Gmail app. How can I be sure to handle this app correctly as well? The intent filter seems to work - I am prompted for the browser or my app, however upon selecting my app, it is forced to close. Here is the error from my logcat:

06-02 01:23:11.337: ERROR/AndroidRuntime(11145): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.Example}: java.lang.NullPointerException
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at androi开发者_开发问答d.os.Handler.dispatchMessage(Handler.java:99)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.os.Looper.loop(Looper.java:123)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at java.lang.reflect.Method.invokeNative(Native Method)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at java.lang.reflect.Method.invoke(Method.java:521)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at dalvik.system.NativeStart.main(Native Method)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): Caused by: java.lang.NullPointerException
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at com.example.android.Example.onCreate(Example.java:301)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145):     ... 11 more

Also, here is my code for handling the incoming intent in onCreate:

if (getIntent().getCategories().contains("android.intent.category.BROWSABLE")){
     try{
        Uri uri = getIntent().getData();
        String url = uri.getFragment();
        //parse url and handle its contents
     }catch(Exception e){
        Toast.makeText(this, "could not open url", Toast.LENGTH_LONG).show();
     }
  }

Any help would be much appreciated!


getIntent().getCategories() will return null if there are no categories. To fix the problem, I changed this if statement to:

if (getIntent().getAction().equals("android.intent.action.VIEW")){...}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜