@@ -808,13 +808,16 @@ public String toString() {
808808 * always present to the user a list of the things they can do, with a
809809 * nice title given by the caller such as "Send this photo with:".
810810 * <p>
811+ * If you need to grant URI permissions through a chooser, you must specify
812+ * the permissions to be granted on the ACTION_CHOOSER Intent
813+ * <em>in addition</em> to the EXTRA_INTENT inside. This means using
814+ * {@link #setClipData} to specify the URIs to be granted as well as
815+ * {@link #FLAG_GRANT_READ_URI_PERMISSION} and/or
816+ * {@link #FLAG_GRANT_WRITE_URI_PERMISSION} as appropriate.
817+ * <p>
811818 * As a convenience, an Intent of this form can be created with the
812819 * {@link #createChooser} function.
813820 * <p>
814- * If the target {@link #EXTRA_INTENT} contains {@link ClipData}, you should
815- * also copy it to this intent along with relevant flags, such as
816- * {@link #FLAG_GRANT_READ_URI_PERMISSION}.
817- * <p>
818821 * Input: No data should be specified. get*Extra must have
819822 * a {@link #EXTRA_INTENT} field containing the Intent being executed,
820823 * and can optionally have a {@link #EXTRA_TITLE} field containing the
@@ -828,6 +831,14 @@ public String toString() {
828831 /**
829832 * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
830833 *
834+ * <p>Builds a new {@link #ACTION_CHOOSER} Intent that wraps the given
835+ * target intent, also optionally supplying a title. If the target
836+ * intent has specified {@link #FLAG_GRANT_READ_URI_PERMISSION} or
837+ * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, then these flags will also be
838+ * set in the returned chooser intent, with its ClipData set appropriately:
839+ * either a direct reflection of {@link #getClipData()} if that is non-null,
840+ * or a new ClipData build from {@link #getData()}.
841+ *
831842 * @param target The Intent that the user will be selecting an activity
832843 * to perform.
833844 * @param title Optional title that will be displayed in the chooser.
@@ -843,12 +854,26 @@ public static Intent createChooser(Intent target, CharSequence title) {
843854 }
844855
845856 // Migrate any clip data and flags from target.
846- final ClipData targetClipData = target .getClipData ();
847- if (targetClipData != null ) {
848- intent .setClipData (targetClipData );
849- intent .addFlags (target .getFlags ()
850- & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION ));
857+ int permFlags = target .getFlags ()
858+ & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION );
859+ if (permFlags != 0 ) {
860+ ClipData targetClipData = target .getClipData ();
861+ if (targetClipData == null && target .getData () != null ) {
862+ ClipData .Item item = new ClipData .Item (target .getData ());
863+ String [] mimeTypes ;
864+ if (target .getType () != null ) {
865+ mimeTypes = new String [] { target .getType () };
866+ } else {
867+ mimeTypes = new String [] { };
868+ }
869+ targetClipData = new ClipData (null , mimeTypes , item );
870+ }
871+ if (targetClipData != null ) {
872+ intent .setClipData (targetClipData );
873+ intent .addFlags (permFlags );
874+ }
851875 }
876+
852877 return intent ;
853878 }
854879
@@ -3077,6 +3102,17 @@ public static Intent createChooser(Intent target, CharSequence title) {
30773102 * saw. This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
30783103 */
30793104 public static final int FLAG_ACTIVITY_TASK_ON_HOME = 0X00004000 ;
3105+ /**
3106+ * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3107+ * upon starting the activity the system will also clear any system dialogs that
3108+ * are currently shown. This is intended primarily for any actions that are
3109+ * associated with buttons in a notification: tapping on the button to launch
3110+ * the activity needs to also dismiss the notification window (which is one
3111+ * of the system dialogs); setting this flag on the Intent associated with that
3112+ * action will ensure that and other system dialogs are dismissed so that the
3113+ * user arrives in the new activity.
3114+ */
3115+ public static final int FLAG_ACTIVITY_CLOSE_SYSTEM_DIALOGS = 0X00002000 ;
30803116 /**
30813117 * If set, when sending a broadcast only registered receivers will be
30823118 * called -- no BroadcastReceiver components will be launched.
0 commit comments