Attach txt file and send to bluetooth - android

How i can send the txt file that i created with the FileOutputStream trought of screemShare
i can also not found the file path
//x = "/data/data/" + getPackageName() +"/pec.txt";
this is my code:
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
Uri uri = Uri.parse(x);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
intent.putExtra(android.content.Intent.EXTRA_TEXT, "PEC");
startActivity(Intent.createChooser(intent,"Imprimir"));

Check this example that work for me HERE

Related

android studio share CSV file request contain no data

I want to share my csv file to any action like Bluetooth, send to email ,etc
final String filename = Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, filename);
sharingIntent.setType("text/comma_separated_values/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
the output will be no request containt no data
I think that the filename requires a file:// prefix. Android, for sharing any types of file requires a universal identifier or a Uri.
final String fileUriString = "file://" + Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Also, change the type to text/csv.
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( fileUriString ) ) ;
sharingIntent.setType("text/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
See this answer for more.

share file over bluetooth opp in Android N

What i am trying is to share a file over bluetooth. I have tried below two methods to pass the file name to the ACTION_SEND intend. share activity is pop'ing up and when i touch the connected bluetooth device, i get a toast saying Bluetooth share: File Unknown file not sent. Both the method fails.
public void pushFileOverOpp(String filename) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setPackage("com.android.bluetooth");
intent.setType("audio/mp3");
File f = new File(Environment.getExternalStorageDirectory(), "images");
File sample = new File(f, "sample.mp3");
Uri u = Uri.parse(sample.toString());
intent.putExtra(Intent.EXTRA_STREAM, u);
mContext.startActivity(intent);
}
Error , Log-
OppService: URI : /storage/emulated/0/images/sample.mp3
OppService: HINT : null
OppService: FILENAME: null
OppService: MIMETYPE: audio/mp3
File f = new File(mContext.getFilesDir(), "images");
File sample = new File(f, "sample.mp3");
Uri u = FileProvider.getUriForFile(mContext,
BuildConfig.APPLICATION_ID + ".provider", sample);
intent.putExtra(Intent.EXTRA_STREAM, u);
Error, Log-
OppService: URI : content://com.example.com.test.provider/tester/images/sample.mp3
OppService: HINT : null
OppService: FILENAME: null
I have checked the android source code, This error comes when filename is null. Log also says filename is null. But i could not figure out the exact reason. Could someone Please help me out here, what is wrong with my code.
After some study i understood the problem. There were two issues-
xml tag for external storage(/sdcard/) directory was wrong in xml file.
I changed as below.
<root-path
name="root"
path="/" />
URI permission was not granted
mContext.grantUriPermission("com.android.bluetooth", u,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
After modifying with above lines of code, File share is working !
full working code-
public boolean pushFileOverOpp(String filename) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("*/*"); // supports all mime types
intent.setPackage("com.android.bluetooth"); //bluetooth package name, default opp
File folder = new File(Environment.getExternalStorageDirectory(), "images");
File file = new File(folder, filename);
if (!file.exists()) {
Logger.e("No such file " + filename + " exists!");
return false;
}
Uri u = FileProvider.getUriForFile(mContext, mContext.getPackageName() + ".provider", file);
intent.putExtra(Intent.EXTRA_STREAM, u);
mContext.grantUriPermission("com.android.bluetooth", u,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Logger.d("Sharing file over bluetooth " + folder.toString());
mContext.startActivity(intent);
return true;
}
Thanks.
Please refer this code , it works and share the files using createChooser method.
ArrayList<Uri> arrayList2 = new ArrayList<>();
String MEDIA_PATH = new String(Environment.getExternalStorageDirectory() +
"/NewCallLogs/audio.mp3");
File files = new File(MEDIA_PATH);
Uri u = Uri.fromFile(files);
arrayList2.add(u);
Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
share.setData(Uri.parse("mailto:"));
share.setType("audio/mpeg");
share.putExtra(android.content.Intent.EXTRA_STREAM, arrayList2);
try {
startActivity(Intent.createChooser(share, "Share..."));
// getActivity().finish();
Log.i("Finished sharing.", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(), "nothing shared.", Toast.LENGTH_SHORT).show();
}
For sharing the file only in bluetooth
ArrayList<Uri> arrayList2 = new ArrayList<>();
String MEDIA_PATH = new String(Environment.getExternalStorageDirectory() +
"/NewCallLogs/audio.mp3" );
File files = new File(MEDIA_PATH);
Uri u = Uri.fromFile(files);
arrayList2.add(u);
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setData(Uri.parse("mailto:"));
share.setType("audio/mpeg");
share.setPackage("com.android.bluetooth");
share.putExtra(android.content.Intent.EXTRA_STREAM, arrayList2);
startActivity(share);

sharing gif with telegram android

I want to share an animated gif file with telegram. I'm using following code:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/gif");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment
.getExternalStorageDirectory()
+ FOLDER_NAME
+ fileName + ".gif"));
share.setPackage("org.telegram.messenger");
startActivity(share);
this code open telegram but when I select a chat; there is not any thing to share.
Excuse me for bad English.
I solved it by changing code to
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/gif");
String imagePath = Environment
.getExternalStorageDirectory()
+ FOLDER_NAME
+ fileName + ".gif";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("org.telegram.messenger");
startActivity(share);

The mp3 files of my app are not sent through gmail

I have a problem, I'm triying to send a mp3 file to gmail.
My code works good so far for whatsapp, hotmail, bluetooth... but it doesn't work with gmail
This is my code:
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getAbsolutePath() + "/" +"miApp"+"/tono.mp3";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("audio/mp3");
intent.putExtra(Intent.EXTRA_SUBJECT, "Asunto");
intent.putExtra(Intent.EXTRA_TEXT, "Prueba");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///" + path));
startActivity(intent);
I try with various types of mime but with the same results
"audio/x-mpeg-3"
"video/mpeg"
"video/x-mpeg"
"audio/mpeg"
What's wrong?
This worked for me
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("audio/mp3");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/miApp/tono.mp3"));
startActivity(i);

How to send csv file as attachment in android?

Hi i am developing an android application with email functionality. Here i need to send a CSV file from my path data/data/mypackage/files folder. I am storing the csv file there.It is saving there good.My csv file size is just 245 bytes only. But when i tried to send that file throught mail functionality of android is displaying "File too Large to attach.." message is displaying.
Here is my code:
String filelocation="file:///data/data/my package/files/excerDB.zip";
final Intent emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"purpletalk.raghu#gmail.com"});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "Attendence Report");
emailIntent .putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(filelocation));
startActivity( emailIntent);
But it is not working for me. Please advice me how can i send my file as a attachment to mail in my application.
i hope this code will help u
String FILE = Environment.getExternalStorageDirectory() + File.separator
+ "Foldername";
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// sendIntent.setType("text/html");
sendIntent.setType("application/csv");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
String temp_path = FILE + "/" + "Filename.csv";
File F = new File(temp_path);
Uri U = Uri.fromFile(F);
sendIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(sendIntent, "Send Mail"));
Enjoy this code!

Categories

Resources