繁体   English   中英

Android:获取屏幕截图并将其发布到Facebook墙

[英]Android: Take Screenshot and post it to facebook wall

有人能帮我吗? 我要截屏并将其发布到Facebook墙上(带有消息)! 我已经阅读了多个主题和论坛,但是找不到适合我的东西! 我已经有了facebook SDK!

非常感谢!

使用这种方式捕获视图图像。

View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "yourImageName.jpg");
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(myPath);
    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.flush();
    fos.close();
    MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

这里v是根布局,然后使用SDK 3.5在Facebook中发布照片。

像这样

    private SimpleFacebook mSimpleFacebook;
     mSimpleFacebook = SimpleFacebook.getInstance(this);
    BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
       // create Photo instace and add some properties
    Photo photo = new Photo(bitmap);
    photo.addDescription("Screenshot from sample application");
    photo.addPlace("110619208966868");
    // publish
    mSimpleFacebook.publish(photo, new OnPublishListener()
    {
        @Override
        public void onFail(String reason)
        {
        mProgress.hide();
        // insure that you are logged in before publishing
        Log.w(TAG, "Failed to publish");
        }
        @Override
        public void onException(Throwable throwable)
        {
               mProgress.hide();
            Log.e(TAG, "Bad thing happened", throwable);
        }
        @Override
        public void onThinking()
        {
         // show progress bar or something to the user while publishing
          mProgress = ProgressDialog.show(this, "Thinking",
        "Waiting for Facebook", true);
        }
        @Override
        public void onComplete(String id)
        {
            mProgress.hide();
            toast("Published successfully. The new image id = " + id);
        }
    });

暂无
暂无

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

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