3

(1) 我正在尝试仅在 Android 手机中从 gmail 和蓝牙连接发送或传输 excel 文件。(2) 我的代码成功,文件传输完成。(3) 当我点击我的 dataTransfer 按钮时,它显示了多个发送文件的选项 (4) 像 gmail、蓝牙和 wifi 以及消息和共享到剪贴板 (5) 我不希望有几个选项来发送文件。(6) 我只需要两个共享选项——gmail 和蓝牙。

(7) 我遇到了这个:[如何以编程方式在 android 上使用蓝牙发送文件?][1]

我的代码:

 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();
}

注意:我的代码正在成功运行。

注意:我想要那个,只有两个共享选项..请任何人修改我的代码并帮助我..谢谢提前..

4

1 回答 1

1

(1) 我找到了我的问题的输出。它的工作非常好。

我的代码:

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);
   }

注意:此代码运行良好。

于 2013-02-06T05:20:52.993 回答