Android transfer excel file to gmail and bluetooth via Only
(1) I am trying to send or transfer excel file from gmail and bluetooth connection only on android phone. (2) My code completed successfully and file transfer completed. (3) when I click the dataTransfer button, it shows more than one option to send a file (4) like gmail, bluetooth and wifi, as well as Messaging and Share to Clipboard (5) I don't want multiple options to send a file. (6) I only need two Share options - gmail and bluetooth.
(7) I came across this: [How to send a file using bluetooth to android programmatically?] [1]
My code:
if (curCSV.getCount() != 0) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Diabetic Report File");
i.putExtra(Intent.EXTRA_TEXT,getResources().getString(R.string.find_report));
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(i, "Share Via"));
}
else
{
Toast.makeText(getApplicationContext(), "no data",Toast.LENGTH_SHORT).show();
}
Note. My code completed successfully.
Note. I want for two general options. Please change my code and help me .. Thanks Advance ..
source to share
(1) I found the output for my question. His job is very good.
My code:
List<Intent> targetedShareIntents = new ArrayList<Intent>();
String blue = "com.android.bluetooth" ;
String gmail = "com.android.gmail" ;
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfo.isEmpty())
{
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Log.v("hari", "packageName:"+packageName) ;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
if (resolveInfo.activityInfo.packageName.toLowerCase().contains("blue") ||
resolveInfo.activityInfo.name.toLowerCase().contains("gmail")) {
targetedShareIntent.
putExtra(android.content.Intent.EXTRA_SUBJECT,"Diabetic Report File");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Hello, Please find attached your diabetic report");
Log.v("vivekawe",file.getAbsolutePath()+"");
targetedShareIntent.
putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File(file.getAbsolutePath())));
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
Log.v("hari", "targetedShareIntent.setPackage(packageName);:"
+targetedShareIntent.setPackage(packageName)) ;
}
Log.v("hari", "After If targetedShareIntents:"+targetedShareIntents) ;
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),
"Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.
toArray(new Parcelable[]{}));
Log.v("hari", "chooserIntent:"+chooserIntent) ;
startActivity(chooserIntent);
}
Note: This code works fine.
source to share