i was trying to integrate set as wallpaper option using default gallery app, I don't know how to send the image to gallery using intent. I am attaching fb app samples how its look like.
String root = Environment.getExternalStorageDirectory().toString();
new File(root + "/"+Constants1.APPNAME).mkdirs();
File fileForImage = new File(root + "/"+Constants1.APPNAME, pos + ".jpg");
if (fileForImage.exists()) fileForImage.delete();
try {
FileOutputStream out = new FileOutputStream(fileForImage);
arg0.compress(Bitmap.CompressFormat.PNG, 100, out);
Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent emailIntent = new Intent(Intent.ACTION_ATTACH);
emailIntent.setType("image/png");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
startActivityForResult(Intent.createChooser(emailIntent, pos+".jpg"),0);
The problem is that the image is not passing to the gallery..
Intent emailIntent = new Intent(Intent.ACTION_ATTACH_DATA);
emailIntent.setDataAndType(Uri.fromFile(fileForImage), "image/*");
//emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
startActivity(emailIntent);
Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();
Related
Hello evrybody i'm tryng to share an image on messenger but i don't know why my code doesen't work, I've followed the official guide, https://developers.facebook.com/docs/messenger/android
someone can told me why doese'nt work?
public void sendMessage(){
Bitmap adv= takePic(HomeActivity.livelloCurrent.getNumeroLivello());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
adv.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
new FileOutputStream(f).write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
String mimeType = "image/jpeg";
Intent sendIntent = new Intent();
sendIntent.setType(mimeType);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "<---MY TEXT--->.");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(),"Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
/** //withSDK-->// ShareToMessengerParams shareToMessengerParams = ShareToMessengerParams.newBuilder(ContentUri, mimeType).build();
MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, shareToMessengerParams);**/
}
Im sure that the file creation work cause i have tested it . in testing I get the following error from messenger "Sorry, Messenger was not able to process the file".
how can i solve ?
Replace:
Uri.parse(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg")
with:
Uri.fromFile(f)
I need to share an image (.png format) with transparent background, through sent_action intent.
I searched a lot and tried a lot of samples but couldn't find the solution.
The is this method in witch the image will get shared directly from the resources, but for some reason from some point it has stop working.
Uri url = Uri.parse("android.resource://"
+ getPackageName() + "/" + R.drawable.ic_launcher);
Intent share_intent = new Intent();
share_intent.setAction(Intent.ACTION_SEND);
share_intent.setType("image/png");
share_intent.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(new File(url.toString())));
startActivity(Intent.createChooser(share_intent, "choose app"));
and there is this function which works fine, the problem is it adds a black background to the image.
private void share3()
{
Bitmap bitmap;
OutputStream output;
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/Gallery/");
dir.mkdirs();
File file = new File(dir, "ic_launcher" + ".png");
try {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
output = new FileOutputStream(file);
bitmap. compress(Bitmap.CompressFormat.PNG/*Bitmap.CompressFormat.PNG*/, 0, output);
output.flush();
output.close();
Uri uri = Uri.fromFile(file);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "choose app"));
} catch (Exception e) {
e.printStackTrace();
}
}
I need to share the image from "raw" folder in the resources and share it without background. What should I do?
I found the problem, It is telegram itself. Telegram adds a black background to .png images you share.
Try this ..its work for me to share image from drawable folder.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/LatestShare.png";
OutputStream out = null;
File file = new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path = file.getPath();
Uri bmpUri = Uri.parse("file://" + path);
Intent shareIntent = new Intent();
shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/png");
startActivity(Intent.createChooser(shareIntent, "Share with"));
I am writing an app to share image.
I wrote the code but getting problems.
What I am doing
1: Saving the image temporarily in Internal Stoarge
2: Passing the URI to share the image.
Image is successfully saved in internal storage but not getting share on whatsapp.
When I share it on whatsapp, Whatsapp get opens, I select recipient, whatsapp processes it and says "Retry".
Code:
public void shareImage(View V)
{
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.download);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "myDownloadedImage.jpg");
try
{
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
Toast.makeText(this, "Some error in Writing"+e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
Uri downloadLocation=Uri.fromFile(file);
share.putExtra(Intent.EXTRA_STREAM, downloadLocation);
startActivity(Intent.createChooser(share, "Share Image"));
}
Image succesfully get saved on internal storage but not getting shared on whatsapp.
The screenshot is below. We can see images are not shared successfully.
Use below code to fetch image and make uri:
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
Now pass the bmpUri in:
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
This should make your image share.
I saw other questions about this, tried their answers, but don't work.
I am trying to use the second method from developer.android.com.
(the second white bullet).
I save an image to applications internal memory, with appropriate permissions.
The image (bitmap) is saved successfully, but I can't attach it to a new intent, to share it.
Here is my code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("*/*");//Attach all types (images/text)
FileOutputStream fos;
try{
fos = openFileOutput(myfilename, Context.MODE_WORLD_READABLE);
mybitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
//Image is stored successfully (checked data/data/mypackage/files/myfilename)
Uri uri = Uri.fromFile(getFileStreamPath(myfilename));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
}
catch (Exception e){
// noth
//Log.e(TAG, e.getStackTrace().toString());
}
shareIntent.putExtra(Intent.EXTRA_TEXT, "some text also");
return shareIntent;
}
Applications say that can't attach media items.
Gmail seems to attach item, but it shows nothing when mail send!
Also the uri.getPath returns me:
/data/data/mypackage/files/myfilename,
which is correct
Any ideas?
Thank you!
Edit:
Modified code to use sd card. And still don't get it to work:
File imgDir;
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED))
imgDir = new File(
android.os.Environment.getExternalStorageDirectory(),
".MyAppName/Images");
else imgDir = MyActivity.this.getCacheDir();
if (!imgDir.exists()) imgDir.mkdirs();
File output = new File(imgDir, myFilename);
OutputStream imageFileOS;
try{
Uri uriSavedImage = Uri.fromFile(output);
imageFileOS = getContentResolver().openOutputStream(
uriSavedImage);
bitmapBookCover.compress(Bitmap.CompressFormat.PNG, 90,
imageFileOS);
imageFileOS.flush();
imageFileOS.close();
//Again image successfully saved
shareIntent.putExtra(Intent.EXTRA_STREAM, uriSavedImage);
}
catch (Exception e){
// noth
}
Please try usiing setData() instead of putExtra(), here android developer site - intent set data
I am stuck. I am converting a LinearLayout to a Bitmap, saving it, and then E-mailing it. The issue I have is I want to set the file name so it overwrites the previous file name. The main purpose is to email the LinearLayout as an image. From what I read you have to save it to the SD card first. I am fine with that but I only want to have one saved image at all times. I am getting a file name with what seems like a random 13 digit file name like (1329676773253.jpg) Here is the code.
void image() {
llImage.setDrawingCacheEnabled(true);
test2 = Bitmap.createBitmap(llImage.getDrawingCache());
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "001");
values.put(Images.Media.DISPLAY_NAME, "ast.jpg");
values.put(Images.Media.DATE_ADDED, System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri2 = getContentResolver().insert(
Images.Media.EXTERNAL_CONTENT_URI, values);
try {
OutputStream outStream = getContentResolver()
.openOutputStream(uri2);
test2.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Log.d("done", "done");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri2);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
Html.fromHtml("" + finalEmail));
startActivity(Intent.createChooser(emailIntent, "Email:"));
}
You could simply write to file with FileOutputStream:
FileOutputStream outStream = new FileOutputStream("filename.jpg");