Android Studio:分享到Facebook Messenger

时间:2015-08-10 21:49:23

标签: android facebook share

我正在使用最新的facebook SDK,我正在尝试共享我设备上的图像。我已经尝试了一切,现在我不知道该怎么做,但转向你寻求帮助。这是代码:

        String mimeType = "image/gif";


  Uri contentUri = Uri.parse("/storage/emulated/0/animated.gif");
  // contentUri points to the content being shared to Messenger
        ShareToMessengerParams shareToMessengerParams =
                ShareToMessengerParams.newBuilder(contentUri, mimeType)
                        .build();

// Sharing from an Activity
        MessengerUtils.shareToMessenger(
                this,
                1,
                shareToMessengerParams);

所以这给了我这个错误(来自我的LogCat):

icky.messengersayit E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.inc.nicky.messengersayit, PID: 27783
java.lang.IllegalStateException: Could not execute method of the activity
        at android.view.View$1.onClick(View.java:3969)




FATAL EXCEPTION: main
Process: com.inc.nicky.messengersayit, PID: 13162
java.lang.IllegalStateException: Could not execute method of the activity
        at android.view.View$1.onClick(View.java:3969)
        at android.view.View.performClick(View.java:4637)
        at android.view.View$PerformClick.run(View.java:19422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5586)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at android.view.View$1.onClick(View.java:3964)
            at android.view.View.performClick(View.java:4637)
            at android.view.View$PerformClick.run(View.java:19422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5586)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalArgumentException: Unsupported URI scheme: null
        at com.facebook.messenger.ShareToMessengerParams.<init>(ShareToMessengerParams.java:106)
        at com.facebook.messenger.ShareToMessengerParamsBuilder.build(ShareToMessengerParamsBuilder.java:120)
        at com.inc.nicky.messengersayit.PersonalSettings.shareFile(PersonalSettings.java:193)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3964)
            at android.view.View.performClick(View.java:4637)
            at android.view.View$PerformClick.run(View.java:19422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5586)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

更新logcat之后我猜想这是重要的一行:

Caused by: java.lang.IllegalArgumentException: Unsupported URI scheme: null
        at com.facebook.messenger.ShareToMessengerParams.<init>(ShareToMessengerParams.java:106)
        at com.facebook.messenger.ShareToMessengerParamsBuilder.build(ShareToMessengerParamsBuilder.java:120)

这是因为您没有提供完全限定的URI。关于facebook sdk:

  

本地内容的uri。必须是file://,content://或res:// URI。