我已经设置了意图过滤器来处理我的应用程序的某些电子邮件链接。这在 Android 的基本邮件程序中运行良好。我单击该链接,系统会提示我是使用浏览器还是我的应用程序打开它,并在选择我的应用程序后正确处理。使用 Gmail 应用程序的情况并非如此。我怎样才能确保正确处理此应用程序?意图过滤器似乎工作 - 提示我使用浏览器或我的应用程序,但是在选择我的应用程序后,它被强制关闭。这是来自我的 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 android.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
另外,这是我在 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();
}
}
任何帮助将非常感激!