I'm new to Android Development.
I'm trying to make an application where I load an image, edit and save it, and transfer the image through bluetooth and email.
It seems like Android has a built in tools that I can use to easily implement bluetooth feature, But I couldn't find any easy and straight-forward tutorials yet.
Can someone help me and give me an example or links to a good tutorial regarding bluetooth feature or email feature?
Please help!
Thanks
use this below script
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/dcim/Camera/filename.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));
With this code, first save file on sdCad, then send it with Bt, email or ...
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
File newSoundFile = new File("/sdcard/101Ringtone.ogg");
Uri mUri = Uri.parse("android.resource://" + getPackageName() + "/"+ RingtoneRaw);
ContentResolver mCr = getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile=null;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(newSoundFile);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("audio/ogg");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(newSoundFile));
startActivity(Intent.createChooser(i, "Share ringtone via:"));
}
});
Related
WhatsApp have added new feature display GIF.
if any one know how to share GIF in whatsapp then let me know
Try this....
private void shareGif(String resourceName){
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "sharingGif.gif";
File sharingGifFile = new File(baseDir, fileName);
try {
byte[] readData = new byte[1024*500];
InputStream fis = getResources().openRawResource(getResources().getIdentifier(resourceName, "drawable", getPackageName()));
FileOutputStream fos = new FileOutputStream(sharingGifFile);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/gif");
Uri uri = Uri.fromFile(sharingGifFile);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share Emoji"));
}
For share gif on whatsapp
/* Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT,title + "\n\nLink : " + link );
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sharePath));
shareIntent.setType("image/*");
startActivity(shareIntent);*/
You just need to set the type of image intent as gif like below
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/gif");
I am trying to share an image to other apps.
From the doc, I understand I have to create a ContentProvider to ensure access to my resource from outside the app. It works with most apps but Facebook Messenger and Messages (com.android.mms). I have the following errors:
FB Messenger: "Sorry, messenger was unable to process the file"
com.android.mms: "Unable to attach. File not supported"
The code I call in the activity to share:
Uri path = Uri.parse("content://com.myauthority/test.png");
Intent shareIntent = new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_STREAM, path).setType("image/png");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share)));
The in my content provider I only override openFile:
#Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
String fileName = uri.getLastPathSegment();
String resName = fileName.replaceAll(".png","");
int resId = getContext().getResources().getIdentifier(resName,"drawable",getContext().getPackageName());
File file = new File(getContext().getCacheDir(), fileName);
Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resId);
FileOutputStream fileoutputstream = new FileOutputStream(file);
boolean flag = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileoutputstream);
try {
ParcelFileDescriptor parcelfiledescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY | ParcelFileDescriptor.MODE_WORLD_READABLE);
return parcelfiledescriptor;
} catch (IOException e) {
e.printStackTrace();
return null;
}
Has anyone an idea or experience to share regarding this issue?
Here am Including my code which i used to share data from my app to facebook app or messenger app.
imageView.setDrawingCacheEnabled(true);
Bitmap bitmap = imageView.getDrawingCache();
File root = Environment.getExternalStorageDirectory();
final File cachePath = new File(root.getAbsolutePath()
+ "/DCIM/Camera/Avi.jpg");
try {
cachePath.createNewFile();
FileOutputStream ostream = new FileOutputStream(
cachePath);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(new File(cachePath
.getAbsolutePath())));
Log.e("Path for sending ",
""+Uri.fromFile(new File(cachePath
.getAbsolutePath())));
mContext.startActivity(intent);
}
}, 3000);
just provide your image uri and use this code.
I'm trying to send email from my application with it's logo.
But I receive the email when the attachment in string format(should be png).
My code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/image");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.fb_share_description));
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://my.package/" + R.drawable.ic_launcher));
Intent chooser = Intent.createChooser(intent, "share");
startActivity(chooser);
What should I do?
You cannot attach files to an email from your internal resources. You must copy it to a commonly accessible area of the storage like the SD Card first.
InputStream in = null;
OutputStream out = null;
try {
in = getResources().openRawResource(R.drawable.ic_launcher);
out = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.png"));
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
e.printStackTrace();
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
//Send the file
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "File attached");
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.png"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
This is required as the resources you bundle with your app are read only and sandboxed to your application. The URI that the email client receives is one it cannot access.
I am attaching an image from drawable folder and sending it in a email.
when I send it from default email client.Image extension(.png) is missing in attachment
and and also the file name is changed itself.
I want t send image with default name(as in drawable) and with .png extension.
this is my code.
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("image/png");
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, "Hey! ");
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(email, "Sending........"));
Please suggest me what is worng in this code
thanks.
You can only attach an image to mail if the image is located in the SDCARD.
So, you'll need to copy the image to SD and then attach it.
InputStream in = null;
OutputStream out = null;
try
{
in = getResources().openRawResource(R.raw.ic_launcher);
out = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.png"));
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
Log.e("tag", e.getMessage());
e.printStackTrace();
}
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "File attached");
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.png"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Hi I want to send an MMS through my application.For that my code is
void sendMMS()
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable = imageView.getDrawable();
Bitmap bitmapPicked = ((BitmapDrawable) drawable).getBitmap();
bitmapPicked.compress(CompressFormat.JPEG, 75, bos);
byte[] image = bos.toByteArray();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
file.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(file);
fo.write(image);
Log.i(TAG, "image = " + image);
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("text/plain");
String[] recipients = new String[] { "" };
intentEmail.putExtra(Intent.EXTRA_EMAIL, recipients);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intentEmail.putExtra(Intent.EXTRA_TEXT, "body of email");
intentEmail.putExtra("sms_body", "body of sms");
intentEmail.setType("image/jpeg");
intentEmail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(intentEmail);
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
}
When users click on a button, so this method is called & it shows a list of available options to perform this action.So for sending MMS user will have to select "Messaging" option.
Although this works fine for Android version 2.3 but when I run the app on version 4.0.3 then in the list of available options it does not show "Messaging" option.Which is must for sending MMS.
And when I remove the lines
intentEmail.setType("image/jpeg");
intentEmail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
then the list shows the "Messaging" option but I can not remove it.
I am really not getting what is the problem with it or may I will have to add something more for version 4.0.3 .
Please help.
Ok I solved the issue.
My new code is
void sendMMS()
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable = imageProduct.getDrawable();
Bitmap bitmapPicked = ((BitmapDrawable) drawable).getBitmap();
bitmapPicked.compress(CompressFormat.JPEG, 75, bos);
byte[] image = bos.toByteArray();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
file.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(file);
fo.write(image);
Log.i(TAG, "image = " + image);
Intent intentMMS = new Intent(Intent.ACTION_SEND);
intentMMS.setType("image/jpg");
intentMMS.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intentMMS.putExtra("sms_body", messageFacebook);
intentMMS.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intentMMS);
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
}