有什么新方法可以直接在fb而不是浏览器中打开fb url吗?
Is there any new way to open fb url directly in fb not browser?
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 中打开 url。
这个post帮助了我,Open Facebook page from Android app?
打开脸书url
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>
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 中打开 url。 这个post帮助了我,Open Facebook page from Android app?
打开脸书url
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>