Bundle intent = getIntent().getExtras();`
cardView=(CardView)findViewById(R.id.card);
final String query = intent.getString("Query1");
db = new DataBaseHelper(Image.this);
Cursor c = db.getData(query);
if (c.getCount() != 0) {
c.moveToFirst();
do {
image = c.getString(5);
title=c.getString(3);
} while (c.moveToNext());
}
txt.setText(title);
img.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(image, "drawable", getPackageName())));
To create an Share Intent for image, you can use following code.
uriToImage is Uri of your image file.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
EDIT - To get URI of drawable image
Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
Use Content Provider(FileProvider) To Share Data as it is Good Practice.
Intent intent = new Intent(Intent.ACTION_SEND);
final String path = "Your File Path";
Uri uri = FileProvider.getUriForFile(YourActivity.this, "com.abc.xy.appname.fileprovider", new File(path));
intent.setDataAndType(uri, "image/*");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
For Multiple File Sharing
ArrayList<Uri> files = new ArrayList<Uri>();
for (int i = 0; i < mfileList.size(); i++) {
File file = new File(mfileList.get(i).get_path());
Uri uri = FileProvider.getUriForFile(YourActivity.this, "com.abc.xy.appname.fileprovider", file);
files.add(uri);
}
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
To Share an Image Stored in Your Drawable.Put this Uri in your Share Intent Extras.
Uri uri = Uri.parse("android.resource://your.package/drawable/image_name");
Check this Link out For Content Provider Setup.
[https://developer.android.com/reference/android/support/v4/content/FileProvider][1]
Related
I'm trying to make a button for sharing an audio file.I get the file format not supported error.I tried all types but always gave the same error(audio/mpeg,audio/aac,audio/wav,audio/ogg,audio/midi,audio/x-ms-wma)
here my codes
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
File f = new File("ses.mp3");
Uri uri = Uri.parse("file://" + f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/mp3");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mactivity.startActivity(Intent.createChooser(share, "Share audio File"));
Toast.makeText(getApplicationContext(), "Song Shared Successfully", Toast.LENGTH_SHORT).show();
}
});
I am not sure but try to use this Intent
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
File imageFileToShare = new File(f.getAbsolutePath());
Uri uri= FileProvider.getUriForFile
(mactivity,mactivity.getPackageName()+".provider",imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
mactivity.startActivity(Intent.createChooser(share, "Share audio File"));
Error showing while capturing image ,I already give the read write storage permission of device
I am using camera intent for taking photo in android 10, But shows following error
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentResolver resolver = getContext().getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "temp");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + "TEMP");
Uri imageUri123 = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
imageUri123);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}else {
File photo = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M?getOutputMediaFileUri(getActivity(), photo):Uri.fromFile(photo));
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
How to display images in full screen from MYSL when the image icon is clicked? Using JSON and intent.
Example Image:
Try with this
Uri uri;
Intent intent = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = Uri.parse("image_route");
} else {
uri = Uri.fromFile(new File("image_route"));
}
String mime = "*/*";
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
if (mimeTypeMap.hasExtension(
mimeTypeMap.getFileExtensionFromUrl(uri.toString())))
mime = mimeTypeMap.getMimeTypeFromExtension(
mimeTypeMap.getFileExtensionFromUrl(uri.toString()));
intent.setDataAndType(uri, mime);
I am new to android i have read mant aricles on this from stackoverflow and other resources but i tried my best to get result
At time of sending i select gmail to send my image but its showing empty file cant be attached
i tried with different images in my package but i get the same response
Here is my code which i tried
Intent intent;
Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + getResources().getResourcePackageName(R.drawable.cursor)
+ '/' + getResources().getResourceTypeName(R.drawable.cursor) + '/' +
getResources().getResourceEntryName(R.drawable.cursor) );
intent=new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
chooser=Intent.createChooser(intent, "Select app to send");
startActivity(chooser);
Hope this helps:
BitmapFactory.Options options = new BitmapFactory.Options();
options.outMimeType = "image/jpeg";
Bitmap bitmap= BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher, options);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Image Description", null);
Uri uri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));
I have created custom intents for the user to choose photos or take a picture.
Here's my Code:
Intent pickIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "new image");
values.put(MediaStore.Images.Media.DESCRIPTION, "saved today");
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraPhotoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPhotoUri);
String pickTitle = "Select or take a new Picture"; // Or get from strings.xml
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
new Intent[]{takePhotoIntent});
startActivityForResult(chooserIntent, REQUEST_CODE_ADD_PHOTO);
now the getContentResolver().insert(...) part creates an empty file on the image directory.How do I delete all of them (empty files) after using the intents. Please help.