Skip to content Skip to sidebar Skip to footer

Proper Way To Share An Image (using Intents)

I create images in my app and want to share these social networks (facebook), mail apps (gmail), and other apps that can 'receive' images. The origin of the problem (I think) is t

Solution 1:

Did you try ParecelableFileDescriptor?

http://developer.android.com/reference/android/os/ParcelFileDescriptor.html

Create with static ParcelFileDescriptor open(File file, int mode, Handler handler, ParcelFileDescriptor.OnCloseListener listener) Create a new ParcelFileDescriptor accessing a given file. static ParcelFileDescriptor open(File file, int mode) Create a new ParcelFileDescriptor accessing a given file.

Receiver side like this: Returning an Input Stream from Parcel File Descriptor using Androids DownloadManager

Solution 2:

You should to make 3 steps. Take picture.

public Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();
}

Save picture.

publicStringsaveBitmap(Bitmap bitmap) {

File imagePath = newFile(Environment.getExternalStorageDirectory() + “/screenshot.png”);
    FileOutputStream fos;
    try {
        fos = newFileOutputStream(imagePath);
        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e(“GREC”, e.getMessage(), e);
    } catch (IOException e) {
        Log.e(“GREC”, e.getMessage(), e);
    }

    return imagePath.getAbsolutePath();
} 

Share to social network.

Post a Comment for "Proper Way To Share An Image (using Intents)"