繁体   English   中英

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

[英]Facebook upload fail error when sharing image through android app

这就是我想要做的!

我正在截取屏幕截图并将其保存在手机中,然后选择相同的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>

我可能会遇到相同的错误。

我通过在AndroidManifest.xml中添加元数据来解决此问题:

<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="{Display name in Facebook API Base Setting}" />

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

您可以在这里找到Facebook API设置页面

暂无
暂无

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

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