facebook sdk 3.5共享Android上的对话框不工作

问题描述:

我一直在谷歌和这个网站两个星期徘徊现在为了找到我的问题的一些答案,但我没有得到任何。我已经完成了一个用户可以拍照的应用程序,并且希望将它们更新到Facebook。现在,我设法做了一个画廊,当用户按下图片时,它在一个名为ViewImage的新类中打开。那里我屁股一些选项菜单,如设置和共享。现在,我希望当用户按共享时,将使用共享对话框(稍后我会尝试打开图)将某些内容张贴到他的Facebook个人资料中。 这里是ViewImage代码,还有一部分是从https://gist.github.com/jacklt/6700201采取:facebook sdk 3.5共享Android上的对话框不工作

public class ViewImage extends Activity { 
    TextView text; 
    ImageView imageview; 
    private int position; 
    private String[] filename; 
    private String[] filepath; 
    private UiLifecycleHelper uiHelper; 
    private static final String TAG_LOG = ViewImage.class.getSimpleName(); 
    private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { 
     @Override 
     public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { 
      Log.d(TAG_LOG, String.format("Error: %s", error.toString())); 
     } 

     @Override 
     public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { 
      Log.d(TAG_LOG, "Success!"); 
     } 
    }; 

    private Session.StatusCallback callback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, Exception exception) { 
      onSessionStateChange(session, state, exception); 
     } 
    }; 

    private void onSessionStateChange(Session session, SessionState state, Exception exception) { 
     if (state.isOpened()) { 
      Log.i(TAG_LOG, "Logged in..."); 
     } else if (state.isClosed()) { 
      Log.i(TAG_LOG, "Logged out..."); 
     } 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     uiHelper = new UiLifecycleHelper(this, callback); 
     uiHelper.onCreate(savedInstanceState); 

     // Get the view from view_image.xml 
     setContentView(R.layout.view_image); ; 

     // Retrieve data from MainActivity on GridView item click 
     Intent i = getIntent(); 

     // Get the position 
     position = i.getExtras().getInt("position"); 

     // Get String arrays FilePathStrings 
     filepath = i.getStringArrayExtra("filepath"); 

     // Get String arrays FileNameStrings 
     filename = i.getStringArrayExtra("filename"); 

     // Locate the TextView in view_image.xml 
     text = (TextView) findViewById(R.id.imagetext); 

     // Load the text into the TextView followed by the position 
     text.setText(filename[position]); 

     // Locate the ImageView in view_image.xml 
     imageview = (ImageView) findViewById(R.id.full_image_view); 

     imageview.setScaleType(ImageView.ScaleType.CENTER_CROP); 

     // Decode the filepath with BitmapFactory followed by the position 
     Bitmap bmp = BitmapFactory.decodeFile(filepath[position]); 

     bmp = GridViewAdapter.adjustImageOrientation(bmp,filepath[position]); 

     // Set the decoded bitmap into ImageView 
     imageview.setImageBitmap(bmp); 

    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); 
    } 

    @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(); 
    } 



    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.view_image, menu); 
     return true; 
    } 


    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     if (item.getItemId() == R.id.action_home) { 
      { 
       Intent i = new Intent(); 
       i.setClass(this, Main.class); 
       startActivity(i); 
      } 
      return true; 
     } else if (item.getItemId() == R.id.action_settings) { 
      { 
       Intent i = new Intent("net.lirazarviv.Setting"); 
       startActivity(i); 
      } 
      return true; 
     } else if (item.getItemId() == R.id.action_share) { 
      { 
       if (FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { 
        FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) 
          .setName("Titolo") 
          .setLink("http://developer.neosperience.com/android") 
          .setDescription("Hello from Neosperience Developer") 
          .setPicture("http://lh3.googleusercontent.com/-P4JBVTv_kSI/AAAAAAAAAAI/AAAAAAAAAAs/bZptjIhkWu4/s265-c-k-no/photo.jpg") 
          .build(); 
        uiHelper.trackPendingDialogCall(shareDialog.present()); 

       } 
       else { 
        Log.d(TAG_LOG, "Success!"); 
       } 
      } 

      return true; 
     } else return super.onOptionsItemSelected(item); 
    } 
} 

当我按下分享按钮,该应用程序崩溃只是..一些帮助,这将是赞赏! p.s.这里是logcat:

E/PlayerDriver( 83): PlayerDriver::handleTvOut state=[1] 
10-03 15:21:45.893 E/PlayerDriver( 83): PlayerDriver::it is not a DRM file.So don't suspend TVOUT 
10-03 15:21:53.440 E/AndroidRuntime(1467): FATAL EXCEPTION: main 
10-03 15:21:53.440 E/AndroidRuntime(1467): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.lirazarviv.origame/net.lirazarviv.origame.ViewImage}: java.lang.NullPointerException: Argument 'applicationId' cannot be null 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.os.Looper.loop(Looper.java:123) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread.main(ActivityThread.java:3687) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at dalvik.system.NativeStart.main(Native Method) 
10-03 15:21:53.440 E/AndroidRuntime(1467): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.facebook.internal.Validate.notNull(Validate.java:29) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.facebook.Session.<init>(Session.java:227) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.facebook.Session.<init>(Session.java:212) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:87) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at net.lirazarviv.origame.ViewImage.onCreate(ViewImage.java:58) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 
10-03 15:21:53.440 E/AndroidRuntime(1467):  ... 11 more 
10-03 15:21:53.748 E/  ( 128): Dumpstate > /data/log/dumpstate_app_error 
+0

什么是logcat的错误? –

+0

我添加它,希望它有帮助 – arvivlx2

这是因为你没有在清单中设置应用程序ID。通常情况下,如果您已经使用其他SDK功能(例如Login),那么您已经拥有它的清单,但是如果您没有,请按照以下方法添加它:

在您的AndroidManifest .XML,添加类似:

<application> 
    ... 
    <meta-data 
     android:name="com.facebook.sdk.ApplicationId" 
     android:value="@string/app_id" /> 
</application> 

然后,在你的价值观/ strings.xml中,添加

<string name="app_id">YOUR_FACEBOOK_APP_ID</string> 
+0

我不知道为什么,但当我复制 - 通过你的解决方案,它确实工作!我已经把它添加到清单之前,我不知道它为什么不好...非常感谢你! – arvivlx2