this is my first post here so I am really sorry if I break some rules. Please correct me where I go wrong.
Now to the question, I have searched back and forth on stackoverflow and other websites/internet but I can't seem to find the right answer.
I am trying to attach a jpg frm the drawable folder to my MMS.
I am using this code for sending MMS.
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM,path);
startActivity(intent);
The intent works fine for me and the mms application loads IF i don't add the URI path to it.
However, when I add the path, the app crashes.
I've tried numerous ways of adding the image from the drawable that i found here at stackoverflow or other websites.
I am writing some of them here, all of them didn't work for me.
Uri path = Uri.parse("android.resource://com.android.MYAPP/drawable/imagename");
And
String uri = "drawable/icon";
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
Uri path = Uri.parse("android.resource://com.android.MMSAPP/drawable/" + imageResource);
And
Uri path = Uri.parse("android.resource://com.android.MMSAPP/" + R.drawable.imageName);
I have stuck with this problem from the last several days and I would be really thankful if I can find the right answer.
Thank you so much in advance.
I am still not sure why I was getting error with code that was working fine for everyone else, however, I used the assetmanager and things worked for me.
Do this.
Uri path = Uri.parse("android.resource://your.package.name/" + R.drawable.sample_1);
Convert the URI to a string and you will be able to send it via MMS
Related
I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */
i am trying to set ImageView as resource of uri.pare.
to perform this task i tried this but it's not working: failed to load image
method 1:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");
intent.putExtra("mimeType", "image/*");
startActivity(Intent.createChooser(intent, "Set as:"));
method 2:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");
startActivity(intent);
i am not able to set ImageView as resource of uri.parse, so please help me how do i set ImageView as resource of uri.parse
i found a code but i am not understanding how to adjust this code with my code:
this is i found:
ImageView imgView = (ImageView) findViewById(R.id.image3);
imgView.setImageURI(Uri.parse("file://mnt/sdcard/d2.jpg"));
how do i adjust it with my code:
intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");
ImageView.setImageURI only takes Android content URI as stated here:
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/jupslaeAEuo
In other words, it takes things like "file://" or "content://" URI's, not resource ID's like what you are trying to do.
If you want to do that, the only way that I know how, and what I did, was to write the resource to a file and then pass the file path to the ImageView URI. There are many examples of how to write files to the system (including thinking about using the SDCARD, etc.)
I'm pretty sure you could write a ContentProvider that will resolve the "content://" or "file://" schemes using the ContentProvider openFile / openInputStream methods, but I abandoned that before I needed it. I might finish it - if anyone is curious how it works...
"Setting uri.parse resource as ImageView" is not works and i failed to found such a way to
"Set uri.parse resource as ImageView"
the simple and working way is to save image to sd card then use code like this:
intent.setDataAndType(Uri.parse("file://mnt/sdcard/temp_image0.png"),"image/*");
see this post to find out saving image to sd card:
how to save ViewPager Current image to sd card on button click
- We have tried to post image and text using the below code:
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("image/png");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/UserImages/"+ ParseUser.getCurrentUser().getObjectId() + ".png"));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hello test");
startActivity(Intent.createChooser(shareIntent,"Share"));
- We have also tried using shareIntent.setType("*/*"), but still no luck.
- When we are trying to post this on email, only text is appearing in it, and when we tried posting it on whatsapp then only the image was visible.
- We are unable to post both together, can anyone suggest the proper way of doing it.
Thank you very much in advance.
Now your code gonna work due the new updates to whatsapp, before this didn't accept this kind of intent (ACTION_SEND_MULTIPLE) because it accepts only one file at a time.
Now I have downloaded a .pdf file from website and wanna open it with the specified software like "Adobe Reader".How can I achieve this?
You cant. All you can do is fire off an intent and let the system handle it. If the user already has a default app that they've chosen to handle PDFs, that's the one that will open the PDF.
In general it's something like:
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} .......
I have solved this problem by adding the method "Intent.setComponent(pkg,cls);".
PS: I don Not angry about downing my reps.And thank you for giving me the suggestions.
PSS: What I wanna say is "Not everyone will get the same apple." I post this question for I have this problem and it occured in Android App.And Someone told me "Cannot".I post my answer just to tell you Ive solved this(or just mine) problem,and maybe it will help someone who has the problem same as mine.Yeah,this answer may make no sense to you.
PSSS::-)But I still think the API make sense to me and to its Designer.
*PSSSS:*At last,thank you all.And forgive my poor English.
You should first have a look at the intents filters documentation. Then you can start an intent (after adding the intent filter) for your PDF file.
I am simply trying to get the path of an image that the user selects and then convert it into a bitmap. The problem is, only some of the images in the gallery work when selected (by "work" I mean they are found to be a file that exists), while the others claim the file does not exist (even though the image is showing up in the gallery?). Even more strange is that this doesn't seem to be consistent, an image that was at one point considered to "exist" now claims to be nonexistent. My code is below:
-----The Intent-----
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_ACTIVITY);
-----onActivityForResult-----
Uri uri = intent.getData();
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(uri,proj,null,null,null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
BitmapFactory.Options opts = new BitmapFactory.Options();<br/>
opts.inSampleSize = 2;<br/>
Bitmap b = BitmapFactory.decodeFile(cursor.getString(column_index),opts);
Any ideas on this will be greatly appreciated, thank you!
Matt.
Some images in gallery were loaded from external sources (such as Picasa), thus were not stored locally, causing local filepath reading failure. You can distinguish them by reading your uri value. I could not find a fix for this, perhaps this bug http://code.google.com/p/android/issues/detail?id=21234 can lure out a solution soon.