5

有人能告诉我应该在哪里设置一个 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());
    }

我应该怎么做才能为那个例外干杯?

4

1 回答 1

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

我希望它对某人有用。感谢您的同情,请原谅我对这个问题的不关心。

于 2015-04-20T18:22:50.170 回答