我遇到了一个不同的错误。我试图做Facebook Share Dialog但是我在logcat中遇到了这个错误。
10-17 15:44:39.026: E/AndroidRuntime(2534): com.facebook.FacebookException: Unable to create Intent; this likely means the Facebook app is not installed.
我不知道这意味着什么。我试图搜索它,但没有类似的实例。这是我的代码。
TabFour.java
public class TabFour extends Fragment {
private UiLifecycleHelper uiHelper;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_tab_four, container, false);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("book", "https://example.com/book/Snow-Crash.html");
@SuppressWarnings("deprecation")
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "books.reads", "book")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
}
};
}
这是我的logcat。:
答案 0 :(得分:17)
对于那些真正想为未安装Facebook应用的用户构建应用的用户,请务必在ShareDialog构建器(more info here)周围加入此检查:
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setLink("https://developers.facebook.com/android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
答案 1 :(得分:12)
如果用户没有安装应用程序(来自FB的荒谬依赖...),您可以回退到浏览器共享:
String linkString = "https://developers.facebook.com/android";
if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this).setLink(linkString).build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + linkString;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
this.startActivity(intent);
}
答案 2 :(得分:4)
com.facebook.FacebookException:无法创建Intent;这很可能 表示未安装Facebook应用程序
引自第2步@ https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
Facebook SDK使用Facebook的原生应用程序提供身份验证支持。在真实设备上,您只需从Google Play免费安装此应用即可对此进行测试。但是,无法在模拟器上访问Google Play。如果您想在那里测试流程,我们会在您可以安装的SDK中包含一个副本。
Facebook应用程序的可安装APK位于SDK的bin文件夹中,名为FBAndroid-3.5.apk或类似名称。要将其安装到Android模拟器上,您首先需要启动模拟器。
其次,在主Android SDK的platform-tools目录中找到adb工具。在OS X上,当您解压缩Android SDK时,您将选择此位置。在Windows上,SDK安装在您的主目录中,位于AppData \ Local \ Android \ android-sdk
下假设您已将Facebook SDK放置在主目录中,您可以使用adb将APK安装到OS X中正在运行的模拟器中,如下所示:
./adb install ~/facebook-android-sdk-3.5/bin/FBAndroid-3.5.apk
在Windows上,像这样:
adb install%HOMEPATH%\ facebook-android-sdk-3.5 \ bin \ FBAndroid-3.5.apk 完成后,请检查模拟器的应用程序屏幕,检查应用程序是否已正确安装。如果您需要从以前的版本强制升级此应用程序,请在OS X上添加-r标志,如下所示:
./adb install -r ~/facebook-android-sdk-3.5/bin/FBAndroid-3.5.apk
答案 3 :(得分:1)
// 清单文件
<uses-permission android:name="android.permission.INTERNET" />
<强>的build.gradle 强> 编译'com.facebook.android:facebook-android-sdk:4.8.0'
<meta-data
android:name="com.facebook.sdk.ApplicationName"
android:value="@string/app_name" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider1854328631556764"
android:exported="true" />
private CallbackManager callbackManager; // Global variable Declare
private ShareDialog mFacebookShareDialog; // Global variable Declare
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
fbloginButton = (LinearLayout) findViewById(R.id.facebook_button);
mFacebookShareDialog = new ShareDialog(this);
}
当成功完全登录facebook然后致电shareOnFaceboo kMethod其工作
private void shareOnFacebook(){
ShareLinkContent shareContent = new ShareLinkContent.Builder()
.setContentTitle("The Simpson!")
.setContentUrl(Uri.parse("http://www.codecube.in/airbucks-project"))
.build();
mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
mFacebookShareDialog.registerCallback( this.callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
String postID = result.getPostId();
Log.v("MyApp", "Share success!" +result);
Log.v("MyApp", "Share success!" +postID);
Log.v("MyApp", "Share success!" +result.getPostId());
Log.v("MyApp", "Share success!" +result.toString());
Log.v("MyApp", "Share success!" +result);
CommonMethod.showAlert("Sucesssfully post in Fb Post id -> " +postID +" Result " +result ,MainActivity.this);
}
@Override
public void onCancel() {
Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
CommonMethod.showAlert("Post onCancel " ,MainActivity.this);
}
@Override
public void onError(FacebookException e) {
Log.v("MyApp","Share error: " + e.toString());
CommonMethod.showAlert("Post onError "+e ,MainActivity.this);
}
});
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}