2015-10-20 74 views
0

有人可以给我看一小段代码,通过而不是来调用短信应用程序,选择器出现吗?Android SMS Via Intent Without Chooser

我已经看到这在其他应用程序中完成,特别是我试图从InputService(键盘)内做到这一点。我创建了一个具有自定义图像的键盘,需要将其传递给SMS窗口。唯一的方法是创建一个图像的意图,但每次选择器打开,我必须选择SMS应用程序作为收件人。现在我知道,一旦用户选择“始终使用此选项”,它不会再发生,但我宁愿他们不必这样做。

下面是我使用的是现在,除了出现在选择器,工作代码:

fmImageView.buildDrawingCache(); 
Bitmap b = fmImageView.getDrawingCache(); 
FileOutputStream out = new FileOutputStream(filePath+"/sms.png"); 
b.compress(Bitmap.CompressFormat.PNG, 100, out); 
out.flush(); 
out.close(); 
File f = new File(filePath+"/sms.png"); 

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
shareIntent.setData(Uri.parse("smsto:")); 
shareIntent.setType("image/png"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); 
startActivity(shareIntent); 
+1

这个问题已经被问了一个答案。 http://stackoverflow.com/questions/14261025/sending-a-sms-message-from-an-android-application-without-opening-chooser –

+0

如果有选择器出现,那么用户有两个或更多的应用程序广告他们自己作为SMS客户端,并且您无法知道用户想要使用哪些SMS客户端。请允许用户使用*用户*选择的SMS客户端。 – CommonsWare

+0

我不同意用户不得不选择SMS客户端。现在有一个外部键盘可以叫做USC木马程序(https://play.google.com/store/apps/details?id=com.snaps.bradz.usc_torjan_keyboard),它完全符合我想要做的。在键盘上时,它基本上会自行调用并将图像添加到SMS主体。 – O2U

回答

0

尝试使用这个,而不是“图像/ PNG” -

shareIntent.setType("vnd.android-dir/mms-sms");

+0

是的我以前试过,问题是图像不出现在短信主体。 – O2U