Skip to content Skip to sidebar Skip to footer

Android Share Image On Snapchat

I'm using this code to share a screenshot of the score: Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType('image/png'); Uri image = Uri.p

Solution 1:

They Problem was, that I saved the screenshot to the sd-card, but snapchat doesnt have the permission to read files from the external storage. I had to use the app Directory that can only be accesed by my app and had to change the permissions with my own fileprovider (com.test.fileprovider) so that snapchat can acess it. Here is the Code:

IntentsharingIntent=newIntent(Intent.ACTION_SEND);
        sharingIntent.setType("image/jpg");
        sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        FilenewFile=newFile(getContext().getCacheDir(), "share_score.jpg");
        Log.d(getClass().getSimpleName(), newFile.getAbsolutePath());
        Uriimage= FileProvider.getUriForFile(getContext(), "com.test.fileprovider", newFile);
        try {
            // create bitmap screen captureViewv1= v.getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmapbitmap= Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);

            FileOutputStreamoutputStream=newFileOutputStream(newFile);
            intquality=100;
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Throwable e) {
            // Several error may come out with file handling or OOM
            e.printStackTrace();
        }
        sharingIntent.putExtra(Intent.EXTRA_STREAM, image);
        startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));

Solution 2:

Im using this code for Instagram and works fine:

AssetManagerassetFiles= getAssets();
InputStreamistr=null;
Bitmapimage=null;

try {
    istr = assetFiles.open("img.jpg");
} catch (IOException e) {
    e.printStackTrace();
}

image = BitmapFactory.decodeStream(istr);

StringpathofBmp= MediaStore.Images.Media.insertImage(getContentResolver(), image, "Share Text", null);
UribmpUri= Uri.parse(pathofBmp);

IntentsendIntent=newIntent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Share Text");
sendIntent.setType("image/png");
sendIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
sendIntent.setPackage("com.instagram.android");
startActivity(sendIntent);

I hope this snippet help you.

Post a Comment for "Android Share Image On Snapchat"