Question

This code works for "adress" and "sms_body" but not for "image"

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Uri uri=Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/q.png");
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra("address","1234567890");
        i.putExtra("sms_body","This is the text mms");
        i.putExtra(Intent.EXTRA_STREAM,"file:/"+uri);
        i.setType("image/png");
        startActivity(i);

    }   
}

Someone knows why ?

Was it helpful?

Solution 3

I solved my problem. The solution is to use :

i.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));

Instead of :

i.putExtra(Intent.EXTRA_STREAM,uri);

I thank all those who wanted to help me :)

OTHER TIPS

Your error is here

i.putExtra(Intent.EXTRA_STREAM,"file:/"+uri);

instead of you just passed uri into

i.putExtra(Intent.EXTRA_STREAM,uri);

try this is working in my case.

Create bitmap first

ImageView img_user= (ImageView)findViewById(R.id.img_user);

Bitmap screenshot = Bitmap.createBitmap(img_user.getWidth(),img_user.getHeight(), Bitmap.Config.RGB_565);

img_user.draw(new Canvas(screenshot));

Get your image path

String path = "file://"+Environment.getExternalStorageDirectory()+"/q.png";

Use path in URI class

Uri screenshotUri = Uri.parse(path);

Call Intent

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send email using"));

You can see the all structure of my sdcard and image be located at your mentioned path: DDMS show file location

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top