简体   繁体   中英

Android: Take Screenshot and post it to facebook wall

can someone help me? I want to take a screenshot and post this to the facebook wall (with a message)! I have read several topics and forums but i dont find something that worked for me! I already have the facebook SDK!

Thanks a lot!

capture images of view using this way.

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

here v is root layout and than post photo in facebook using SDK 3.5.

like this way

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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