如何捕获无法找到com.facebook.katana.provider.PlatformProvider错误的提供商信息

时间:2014-02-11 05:08:46

标签: android facebook exception try-catch facebook-sdk-3.1

有人能告诉我应该在哪里设置一个try / catch来捕获它吗?

02-10 22:54:35.701: E/ActivityThread(787): Failed to find provider info for com.facebook.katana.provider.PlatformProvider

我已经知道这是因为我没有在手机中安装facebook应用程序。

我想在抛出异常时做一个Toast 这不起作用。

shareButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            // TODO Auto-generated method stub
            try{
            FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(Archivo.this)
            .setLink(pagina)
            .setName(nombre)
            .setPicture(photo)
            .setDescription(brief)
            .build();
            uiHelper.trackPendingDialogCall(shareDialog.present());
            }
            catch(FacebookDialogException ex){
                int duration = Toast.LENGTH_SHORT;
            CharSequence FacebookDialogError="Instale y actualize su version de Facebook";
            Toast toast = Toast.makeText(activity,FacebookDialogError , duration);
            toast.show();

            }
        }
    });

我在facebookdialog收到异常的地方设置了相同的toast,但它仍无效。

 public FacebookDialog build() {
        validate();

        Bundle extras = new Bundle();
        putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
        putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);

        Intent intent = handleBuild(extras);
        if (intent == null) {
            int duration = Toast.LENGTH_SHORT;
            CharSequence FacebookDialogError="Instale y aCtualize su version de Facebook";
            Toast toast = Toast.makeText(activity,FacebookDialogError , duration);
            toast.show();
            throw new FacebookException("Unable to create Intent; this likely means the Facebook app is not installed.");
        }
        appCall.setRequestIntent(intent);

        return new FacebookDialog(activity, fragment, appCall, getOnPresentCallback());
    }

我该怎样做才能为这个例外致敬?

1 个答案:

答案 0 :(得分:0)

很抱歉,如果现在回答我自己的问题为时已晚,但我即将更新此问题的应用程序。 由于问题仍在观看,我将发布故障排除

如果找不到Facebook应用,这是一个后备。

    private void publishFeedDialog(String Link,String Name,String Photo,String Descripcion) {

    Bundle params = new Bundle();
    params.putString("name", Name);
    params.putString("caption",Caption);
    params.putString("description",Descripcion);
    params.putString("link", Link);
    params.putString("picture",Photo);

    WebDialog feedDialog = (
            new WebDialog.FeedDialogBuilder(sEstablecimiento.this,
                    Session.getActiveSession(),
                    params))
            .setOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(Bundle values,
                                       FacebookException error) {
                    if (error == null) {
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                            Toast.makeText(sEstablecimiento.this,
                                    "Posted story, id: "+postId,
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            // User clicked the Cancel button
                            Toast.makeText(sEstablecimiento.this.getApplicationContext(),
                                    "Publish cancelled",
                                    Toast.LENGTH_SHORT).show();
                        }
                    } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(sEstablecimiento.this.getApplicationContext(),
                                "Publish cancelled",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        // Generic, ex: network error
                        Toast.makeText(sEstablecimiento.this.getApplicationContext(),
                                "Error posting story",
                                Toast.LENGTH_SHORT).show();
                    }
                }

            })
            .build();
    feedDialog.show();
}

并使用布尔值来测试ShareDialog是否可以构建

if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
                                FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {

                            FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(myActivity.this)
                                    .setLink("page")
                                    .setName("name")
                                    .setPicture("photo")
                                    .setDescription("description")
                                    .build();
                            uiHelper.trackPendingDialogCall(shareDialog.present());

                        } else {
                            publishFeedDialog("page","name","photo","description");
                        }

我希望它对某人有用。 感谢你的道路,原谅我对这个问题缺乏关心。