人造人.自定义意图选择器



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

你能不能提出任何建议,我应该怎么做才能完成第二个任务?

我相信我可以发送一封带有图像的电子邮件,内容如下:

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:我意识到,我真正需要的是拦截用户点击,如果sms是在意图选择器中选择的。那么,问题是如何实现呢?

1(创建意图以执行共享或发送操作,

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(创建警报对话框以在警报对话框中设置应用程序,

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

在我看来

,它不能完全按照我的意愿完成。

可能的方法是在 PackageManager 类中使用 queryIntentActivities(( 构建自定义应用程序选择器。有用的帖子:根据已安装的Android软件包名称自定义过滤意图选择器

另一种可能的方法是创建自定义弹出窗口 - http://developer.android.com/guide/topics/ui/menus.html#PopupMenu
或浮动上下文菜单 -
http://developer.android.com/guide/topics/ui/menus.html#FloatingContextMenu

看来客户真正想要的只是一些定制Dialog。像这样:

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("E-mail / MMS").setItems(R.array.send_array, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // The 'which' argument contains the index position
            // of the selected item
        }
    });
    return builder.create();
}

除了选定的答案。
您还可以为 Facebook 添加一个控件,因为 Facebook 不能很好地与共享者配合使用:

if (activity.applicationInfo.packageName.toLowerCase().contains("facebook")) {
                    //Share on Facebook
                    ShareLinkContent content = new ShareLinkContent.Builder().
                            setContentUrl(Uri.parse(mLink)).
                            setImageUrl(Uri.parse(mImageURL)).
                                    setContentTitle(mTitle).
                                    setContentDescription(mDescription)
                            .build();
                    com.facebook.share.widget.ShareDialog.show(mActivity, content);
                } else {
                    //Share on selected application
                    ComponentName name = new ComponentName(activity.applicationInfo.packageName,
                            activity.name);
                    shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                    shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                    shareIntent.setComponent(name);
                    mActivity.startActivity(shareIntent);
                }

最新更新