经过2天的研究,我找到了可能的解决方案。此解决方案不允许用户给我的 Facebook 页面点个赞,如果安装,它只允许在 Facebook 应用程序中查看我的 Facebook 页面:
String pageUrl = String.format("fb://facewebmodal/f?href=%s", Constants.OUKITEL_FACEBOOK_PAGE_URL);//replace OUKITEL_FACEBOOK_URL with your page url
Intent operation = new Intent(Intent.ACTION_VIEW, Uri.parse(pageUrl));
try {
if(isPackageInstalled(ctx, packageName)) {
operation.setPackage(packageName);
}
ctx.startActivity(operation);
}catch (Exception e) {
Toast.maketext(MainActivity.this, "Facebook app is not installed")
}
'isPackageInstalled' 是一个私有方法:
public static boolean isPackageInstalled(Context ctx, String packageName) {
PackageManager pm = ctx.getPackageManager();
try {
return pm.getApplicationInfo(packageName, 0).enabled;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}