通过Android应用程序共享图像时Facebook上传失败错误

时间:2017-09-29 10:58:15

标签: android facebook share

这是我想要做的事情!

我正在拍摄截图并将其保存在我的手机中,然后拿起相同的uri并通过facebook整合上传到facebook上进行分享。

我的代码无效,我可以打开Facebook分享对话框,并在那里显示我的截图。但是当我按下发布按钮时,Facebook会显示“你的照片将被上传。”请在通知栏中检查进度。

在通知栏中,我收到一条消息“Facebook上传失败。您的照片无法上传。”

这是我的代码

  private static Bitmap takeScreenShot(Activity activity) {

 View view = activity.getWindow().getDecorView();

        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap b1 = view.getDrawingCache();
        Rect frame = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        int height = activity.getWindowManager().getDefaultDisplay()
                .getHeight();

        Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
                - statusBarHeight);
        view.destroyDrawingCache();
        Log.e("Screenshot", "taken successfully");
        return b;

    }

    public void saveBitmap(Bitmap bitmap) {

        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            File pictureStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            File LuckPercentage = new File(pictureStorage, "Luck Percentage");
            if (!LuckPercentage.exists())
                LuckPercentage.mkdirs();




            File imagePath = new File(LuckPercentage
                    + "/screenshot-" + shot + ".png");
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(imagePath);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                Log.e("Screenshot", "saved successfully");

                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {
                Log.e("GREC", e.getMessage(), e);
            } catch (IOException e) {
                Log.e("GREC", e.getMessage(), e);
            }
            openScreenshot(imagePath);
        }


    }
    private void openScreenshot(File imageFile) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
         uri = Uri.fromFile(imageFile);
        Log.e("path", ""+uri);
        intent.setDataAndType(uri, "image/*");
        //startActivity(intent);
    }

然后,我正在调用一个对话框,我想显示我的屏幕截图和Facebook分享按钮。

 public void open() {

 dialog = new Dialog(context);

  // super(context,R.style.Theme_Dialog_Translucent);

  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

   dialog.setContentView(R.layout.final_calculation);


   dialog.getWindow().getAttributes().windowAnimations = R.style.Theme_Dialog_Translucent;

   screen = (ImageView) dialog.findViewById(R.id.imageView);

 final ShareButton shareButton = (ShareButton)dialog.findViewById(R.id.fb_share_button);


        SharePhoto photo = new SharePhoto.Builder().setImageUrl(uri).build();
         content = new SharePhotoContent.Builder()
                .addPhoto(photo)
                .build();
        shareButton.setShareContent(content);



        shareButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (ShareDialog.canShow(SharePhotoContent.class)) {






            shareDialog.show(content);
        }
    }
});

        dialog.show();
    }

这是我添加到清单

的内容
<manifest>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

 <uses-permission android:name="android.permission.INTERNET"/>

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

 <meta-data
            android:name="com.facebook.sdk.ApplicationName"
            android:value="@string/app_name" />

 <provider

  android:name="com.facebook.FacebookContentProvider"


android:authorities="com.facebook.app.FacebookContentProvider707840309410113"
            android:exported="true" />
</application>
</manifest>

1 个答案:

答案 0 :(得分:0)

我可能会得到同样的错误。

我通过在AndroidManifest.xml中添加元数据来解决它:打击:

{{1}}

com.facebook.sdk.ApplicationName不应该是包名。它实际上代表API SETTING中的显示名称。

您可以找到Facebook API设置页面here