public static Intent getOpenFacebookIntent(Context context,String url) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
}
我使用了這段代碼并且它正在作業,但現在它沒有。我需要任何意圖直接在 Facebook 中打開網址。這篇文章對我有幫助,從 Android 應用打開 Facebook 頁面?
uj5u.com熱心網友回復:
打開臉書網址
private void openFacebookApp() {
String facebookUrl = "www.facebook.com/XXXXXXXXXX";
String facebookID = "XXXXXXXXX";
try {
int versionCode = getActivity().getApplicationContext().getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if(!facebookID.isEmpty()) {
// open the Facebook app using facebookID
(fb://profile/facebookID or fb://page/facebookID)
Uri uri = Uri.parse("fb://page/" facebookID);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else if (versionCode >= 3002850 && !facebookUrl.isEmpty()) {
// open Facebook app using facebook url
Uri uri = Uri.parse("fb://facewebmodal/f?href=" facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else {
// Facebook is not installed. Open the browser
Uri uri = Uri.parse(facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
} catch (PackageManager.NameNotFoundException e) {
// Facebook is not installed. Open the browser
Uri uri = Uri.parse(facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
}
在清單中添加查詢
<queries>
<package android:name="com.google.android.gm" />
<package android:name="com.facebook.katana" />
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/475489.html
上一篇:多個專案react-nativeandroid構建錯誤
下一篇:(BreakingAgain)SDK尚未初始化,請務必先呼叫FacebookSdk.sdkInitialize()。(安卓)
