Android系统.自定义意图选择器

我想知道,有没有办法使用Intent.createChooser方法选择行为?
例如,我有一个图像,我想通过电子邮件发送,如果它被选中(第一个选项).在第二个选项上,我想发送带有此图像链接的短信
(为此我需要复杂的操作 – 将图像上传到服务器,检索下载链接,我想在短信中将其粘贴到短信中)

你能否提出任何建议,我该怎么办才能完成第二项任务?

我相信我可以发送带有这样的图像的电子邮件:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{textMail}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Some Subj"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Some Extra Text"); 
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(fileUri));
startActivity(Intent.createChooser(emailIntent,"Send mail..."));

UPD:我意识到,我真正需要的是拦截用户点击,如果在意图选择器中选择了短信.那么,问题是如何实现它?

解决方法

1)创建Intent以执行共享或发送操作,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL,new String[]{"velmurugan@androidtoppers.com"});
email.putExtra(Intent.EXTRA_SUBJECT,"Hi");
email.putExtra(Intent.EXTRA_TEXT,"Hi,This is Test");

email.setType("text/plain");

2)创建AlertDialog以在alertdialog中设置应用程序,

final Dialog dialog = new Dialog(Custom_chooser.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
WMLP.gravity = Gravity.CENTER;
dialog.getWindow().setAttributes(WMLP);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.about_dialog);
dialog.show();

3)使用ResolveInfo获取与特定意图相关的应用程序列表

List<ResolveInfo> launchables=pm.queryIntentActivities(email,0);
Collections.sort(launchables,newResolveInfo.DisplayNameComparator(pm));

4))将应用程序列表设置为自定义列表视图.

adapter=new AppAdapter(pm,launchables);
lv.setAdapter(adapter);

5)最后,当从列表视图中的应用程序列表中选择应用程序时,抓住特定的应用程序,

ResolveInfo launchable=adapter.getItem(position);
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,activity.name);
email.addCategory(Intent.CATEGORY_LAUNCHER);
email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
email.setComponent(name);
startActivity(email);

有关更多信息,请参阅此链接:http://velmuruganandroidcoding.blogspot.in/2014/01/custom-chooser-android-in-example.html

相关文章

AdvserView.java package com.earen.viewflipper; import an...
ImageView的scaleType的属性有好几种,分别是matrix(默认)...
文章浏览阅读8.8k次,点赞9次,收藏20次。本文操作环境:win1...
文章浏览阅读1.2w次,点赞15次,收藏69次。实现目的:由main...
文章浏览阅读3.8w次。前言:最近在找Android上的全局代理软件...
文章浏览阅读2.5w次,点赞17次,收藏6次。创建项目后,运行项...