简体   繁体   English

Android上的Facebook SDK 3.5共享对话框不起作用

[英]facebook sdk 3.5 share dialog on android not working

I've been wandering in google and this site for two weeks now in order to find some answers for my problem, but i didnt get any. 我已经在Google和这个网站上徘徊了两个星期,以便找到我的问题的答案,但是我没有得到任何答案。 i've done a app in which the users can take pictures and, hopefuly, update them to facebook. 我已经完成了一个应用程序,用户可以在其中拍照,希望将其更新为Facebook。 now, i've manage to do a gallery and when the user press on image, it's open in a new class, called ViewImage. 现在,我已经设法创建了一个图库,当用户按下图像时,它将在一个名为ViewImage的新类中打开。 there i ass some option menu, such as settings and share. 我在那里有一些选项菜单,例如设置和共享。 for now, i want that when the user press share, something will be post to his facebook profile, using share dialog (later i'll try open graph). 现在,我希望当用户按下共享时,会使用共享对话框将某些内容发布到他的Facebook个人资料中(稍后我将尝试打开图形)。 here is the code for ViewImage, some of it is taken from https://gist.github.com/jacklt/6700201 : 这是ViewImage的代码,其中一些摘自https://gist.github.com/jacklt/6700201

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

when i press the share button, the app just crash.. some help with this will be appreciate! 当我按下共享按钮时,应用程序崩溃了。 ps here is the logcat: ps这里是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

It's because you don't have the application id set in your manifest. 这是因为您的清单中没有设置应用程序ID。 Normally, if you're already using other SDK features (like Login), then you would have it in your manifest already, but if you're not, here's how to add it: 通常,如果您已经在使用其他SDK功能(例如Login),那么您便已经将其包含在清单中了,但是如果没有使用,请按以下步骤进行添加:

Within the application tag in your AndroidManifest.xml, add something like: 在您的AndroidManifest.xml的application标签内,添加以下内容:

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

Then, in your values/strings.xml, add 然后,在您的values / strings.xml中,添加

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM