我正试图通过我的Android应用程序在Facebook上进行共享网址链接。下面是代码。 问题,我需要能够检测到帖子是否成功,或者用户取消或其他一些错误,我能够发帖,但我无法得到任何回报。即。永远不会调用onActivityResult。我错过了什么?感谢。
public static void openFacebook(Activity activity, View view, String urlToShare) {
//String urlToShare = "www.korvac.com";
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = activity.getPackageManager().queryIntentActivities(
shareIntent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.startsWith("com.facebook.katana")) {
// "com.facebook.katana" is the package name for Facebook app
// "com.facebook.orca" is for FB Messenger app
shareIntent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;
}
}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u="
+ urlToShare;
shareIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
activity.startActivityForResult(shareIntent, 90);
}
/* Called when the second activity's finished */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 90:
if (resultCode == RESULT_OK) {
Bundle res = data.getExtras();
String result = res.getString("param_result");
Log.d("facebook", "result:"+result);
}
else{
Log.d("facebook", "result:"+ "failed");
}
break;
}
}