【问题标题】:How to know which intent is selected in Intent.ACTION_SEND in android如何知道在android的Intent.ACTION_SEND中选择了哪个intent
【发布时间】:2015-10-06 04:16:55
【问题描述】:

想使用 Android Intent.ACTION_SEND 快速分享内容。我写了一些代码,我可以显示自定义剪切对话框 但我想检查 Intent.ACTION_SEND 中选择的意图,例如,如果我从 Gmail 发送一些文件,我想显示 Toast 消息(从 Gmail 等发送的消息) 这是我的来源

 PackageManager pm = mActivity.getPackageManager();


    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/jpeg");
    Uri photoUri = Uri.parse(path);
    shareIntent.putExtra(Intent.EXTRA_TEXT,  "Downloading your app");

    shareIntent.putExtra(Intent.EXTRA_STREAM, photoUri);


    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
    for (final ResolveInfo app : activityList)
    {
        Log.e("Application pachage",app.activityInfo.name +"package");
        if ((app.activityInfo.name).contains("Bluetooth"))
        {
            Log.e("Application pachage","mee" +"package");
            Toast.makeText(mActivity,"Message sent from Bluetooth",Toast.LENGTH_SHORT).show();
            final ActivityInfo activity = app.activityInfo;
            final 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);
            break;
        }
    }

那么,有可能吗?

【问题讨论】:

    标签: android android-intent android-bluetooth


    【解决方案1】:

    仅在 Android 5.1+ 上,如果您使用 the three-parameter flavor of createChooser(),您可以在其中提供一个 IntentSender,用于通知选择。

    否则,您需要滚动自己的选择器样式 UI,然后使用用户的选择来制作明确的 Intent 以将用户路由到请求的活动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多