Android - 在打开FB本机应用程序时找不到处理Intent的Activity

时间:2017-01-09 12:34:56

标签: android facebook

我试图通过通知中收到的网址在特定帖子上打开FB应用。

它在大多数设备上都能很好地工作,但它主要在三星S7上崩溃。 我的简单代码:

String url = "fb://post/<post_id>";
Uri target = Uri.parse(url);
notifIntent = new Intent(Intent.ACTION_VIEW, target);
startActivity(notifIntent);

我之前检查过设备上存在FB:

PackageManager packageManager = context.getPackageManager();
try {
     int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
     return "fb://post/" + fb_url;
} catch (PackageManager.NameNotFoundException e) {
     return "https://www.facebook.com/" + fb_url; //normal web mUrl
}

错误日志:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{snip.snipnotifier/snip.snipnotifier.LoadingActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=fb://post/<post_id> }
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3149)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3248)
       at android.app.ActivityThread.access$1000(ActivityThread.java:197)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6872)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=fb://post/251996958535784_295668917501921 }
       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1817)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515)
       at android.app.Activity.startActivityForResult(Activity.java:4076)
       at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
       at android.app.Activity.startActivityForResult(Activity.java:4023)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
       at android.app.Activity.startActivity(Activity.java:4347)
       at android.app.Activity.startActivity(Activity.java:4315)
       at snip.snipnotifier.LoadingActivity.onCreate(LoadingActivity.java:29)
       at android.app.Activity.performCreate(Activity.java:6550)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3248)
       at android.app.ActivityThread.access$1000(ActivityThread.java:197)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6872)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:6)

由于没有活动来处理您在三星S7中的意图。您首先要检查它。

if (sendIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(sendIntent);
} 

希望这有帮助。快乐编码。