Reputation: 105
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 ?
Upvotes: 0
Views: 804
Reputation: 105
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 :)
Upvotes: 2
Reputation: 47817
You can see the all structure of my sdcard and image be located at your mentioned path:
Upvotes: 1
Reputation: 16162
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"));
Upvotes: 2
Reputation: 47817
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.
Upvotes: 2