11935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov/*
21935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * Copyright (C) 2011 The Android Open Source Project
31935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov *
41935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * Licensed under the Apache License, Version 2.0 (the "License");
51935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * you may not use this file except in compliance with the License.
61935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * You may obtain a copy of the License at
71935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov *
81935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov *      http://www.apache.org/licenses/LICENSE-2.0
91935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov *
101935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * Unless required by applicable law or agreed to in writing, software
111935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * distributed under the License is distributed on an "AS IS" BASIS,
121935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * See the License for the specific language governing permissions and
141935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov * limitations under the License.
151935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov */
161935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
171935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganovpackage android.support.v4.content;
181935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
19f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powellimport android.content.ComponentName;
20c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.content.Context;
21f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powellimport android.content.Intent;
22f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powellimport android.os.Build;
23c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
241935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov/**
250574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Helper for accessing features in {@link android.content.Intent}
260574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * introduced after API level 4 in a backwards compatible fashion.
271935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov */
281935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganovpublic class IntentCompat {
291935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
30f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    interface IntentCompatImpl {
31f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        Intent makeMainActivity(ComponentName componentName);
32bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        Intent makeMainSelectorActivity(String selectorAction, String selectorCategory);
33bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        Intent makeRestartActivityTask(ComponentName mainActivity);
34f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    }
35f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell
36f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    static class IntentCompatImplBase implements IntentCompatImpl {
37f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        @Override
38f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        public Intent makeMainActivity(ComponentName componentName) {
39f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            Intent intent = new Intent(Intent.ACTION_MAIN);
40f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            intent.setComponent(componentName);
41f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            intent.addCategory(Intent.CATEGORY_LAUNCHER);
42f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            return intent;
43f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        }
44bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
45bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        @Override
46bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        public Intent makeMainSelectorActivity(String selectorAction,
47bea2fc73637a1d59eb5face20006a27df6893042Adam Powell                String selectorCategory) {
48bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            // Before api 15 you couldn't set a selector intent.
49bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            // Fall back and just return an intent with the requested action/category,
50bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            // even though it won't be a proper "main" intent.
51bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            Intent intent = new Intent(selectorAction);
52bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            intent.addCategory(selectorCategory);
53bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            return intent;
54bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        }
55bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
56bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        @Override
57bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        public Intent makeRestartActivityTask(ComponentName mainActivity) {
58bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            Intent intent = makeMainActivity(mainActivity);
59bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
60bea2fc73637a1d59eb5face20006a27df6893042Adam Powell                    | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
61bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            return intent;
62bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        }
63f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    }
64f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell
65bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    static class IntentCompatImplHC extends IntentCompatImplBase {
66f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        @Override
67f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        public Intent makeMainActivity(ComponentName componentName) {
68f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            return IntentCompatHoneycomb.makeMainActivity(componentName);
69f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        }
70bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        @Override
71bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        public Intent makeRestartActivityTask(ComponentName componentName) {
72bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            return IntentCompatHoneycomb.makeRestartActivityTask(componentName);
73bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        }
74bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    }
75bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
76bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    static class IntentCompatImplIcsMr1 extends IntentCompatImplHC {
77bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        @Override
78bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        public Intent makeMainSelectorActivity(String selectorAction, String selectorCategory) {
79bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            return IntentCompatIcsMr1.makeMainSelectorActivity(selectorAction, selectorCategory);
80bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        }
81f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    }
82f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell
83f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    private static final IntentCompatImpl IMPL;
84f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    static {
85bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        final int version = Build.VERSION.SDK_INT;
86bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        if (version >= 15) {
87bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            IMPL = new IntentCompatImplIcsMr1();
88bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        } else if (version >= 11) {
89f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            IMPL = new IntentCompatImplHC();
90f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        } else {
91f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell            IMPL = new IntentCompatImplBase();
92f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        }
93f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    }
94f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell
951935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    private IntentCompat() {
961935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov        /* Hide constructor */
971935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    }
981935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
991935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    /**
1001935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * Broadcast Action: Resources for a set of packages (which were
1011935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * previously unavailable) are currently
1021935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * available since the media on which they exist is available.
1031935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1041935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * list of packages whose availability changed.
1051935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1061935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * list of uids of packages whose availability changed.
1071935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * Note that the
1081935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * packages in this list do <em>not</em> receive this broadcast.
1091935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The specified set of packages are now available on the system.
1101935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <p>Includes the following extras:
1111935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <ul>
1121935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1131935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * whose resources(were previously unavailable) are currently available.
1141935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link #EXTRA_CHANGED_UID_LIST} is the set of uids of the
1151935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * packages whose resources(were previously unavailable)
1161935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * are  currently available.
1171935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * </ul>
1181935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     *
1191935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <p class="note">This is a protected intent that can only be sent
1201935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * by the system.
1211935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     */
1221935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    public static final String ACTION_EXTERNAL_APPLICATIONS_AVAILABLE =
1231935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov        "android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE";
1241935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
1251935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    /**
1261935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * Broadcast Action: Resources for a set of packages are currently
1271935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * unavailable since the media on which they exist is unavailable.
1281935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1291935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * list of packages whose availability changed.
1301935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1311935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * list of uids of packages whose availability changed.
1321935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * The specified set of packages can no longer be
1331935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * launched and are practically unavailable on the system.
1341935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <p>Inclues the following extras:
1351935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <ul>
1361935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1371935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * whose resources are no longer available.
1381935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link #EXTRA_CHANGED_UID_LIST} is the set of packages
1391935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * whose resources are no longer available.
1401935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * </ul>
1411935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     *
1421935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * <p class="note">This is a protected intent that can only be sent
1431935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * by the system.
1441935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     */
1451935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    public static final String ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE =
1461935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov        "android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE";
1471935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
1481935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    /**
1491935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * This field is part of
1501935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
1511935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
1521935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * and contains a string array of all of the components that have changed.
1531935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     */
1541935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    public static final String EXTRA_CHANGED_PACKAGE_LIST =
1551935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov            "android.intent.extra.changed_package_list";
1561935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov
1571935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    /**
1581935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * This field is part of
1591935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
1601935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
1611935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * and contains an integer array of uids of all of the components
1621935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     * that have changed.
1631935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov     */
1641935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov    public static final String EXTRA_CHANGED_UID_LIST =
1651935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov            "android.intent.extra.changed_uid_list";
166c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
167c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    /**
168200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     * A constant String that is associated with the Intent, used with
169200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     * {@link android.content.Intent#ACTION_SEND} to supply an alternative to
170200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     * {@link android.content.Intent#EXTRA_TEXT}
171200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     * as HTML formatted text.  Note that you <em>must</em> also supply
172200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     * {@link android.content.Intent#EXTRA_TEXT}.
173200e3384b06670f660b283a5715a331be6d85fd3Adam Powell     */
174200e3384b06670f660b283a5715a331be6d85fd3Adam Powell    public static final String EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT";
175200e3384b06670f660b283a5715a331be6d85fd3Adam Powell
176200e3384b06670f660b283a5715a331be6d85fd3Adam Powell    /**
177c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
178c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * this flag will cause a newly launching task to be placed on top of the current
179c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * home activity task (if there is one). That is, pressing back from the task
180c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * will always return the user to home even if that was not the last activity they
181c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * saw. This can only be used in conjunction with
182c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}.
183c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     */
184c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    public static final int FLAG_ACTIVITY_TASK_ON_HOME = 0x00004000;
185c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
186c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    /**
187c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
188c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * this flag will cause any existing task that would be associated with the
189c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * activity to be cleared before the activity is started.  That is, the activity
190c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * becomes the new root of an otherwise empty task, and any old activities
191c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * are finished.  This can only be used in conjunction with
192c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}.
193c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     *
194c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * <p>This flag will only be obeyed on devices supporting API 11 or higher.</p>
195c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     */
196c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    public static final int FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
197f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell
198f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    /**
199f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * Create an intent to launch the main (root) activity of a task.  This
200f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * is the Intent that is started when the application's is launched from
201f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * Home.  For anything else that wants to launch an application in the
202f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * same way, it is important that they use an Intent structured the same
203f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * way, and can use this function to ensure this is the case.
204f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     *
205f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * <p>The returned Intent has the given Activity component as its explicit
206f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * component, {@link Intent#ACTION_MAIN ACTION_MAIN} as its action, and includes the
207f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * category {@link Intent#CATEGORY_LAUNCHER CATEGORY_LAUNCHER}.  This does <em>not</em> have
208f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * {@link Intent#FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_NEW_TASK} set,
209f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * though typically you will want to do that through {@link Intent#addFlags(int) addFlags(int)}
210f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * on the returned Intent.
211f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     *
212f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * @param mainActivity The main activity component that this Intent will
213f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * launch.
214f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * @return Returns a newly created Intent that can be used to launch the
215f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * activity as a main application entry.
216f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     *
217f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * @see Intent#setClass
218f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     * @see Intent#setComponent
219f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell     */
220f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    public static Intent makeMainActivity(ComponentName mainActivity) {
221f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell        return IMPL.makeMainActivity(mainActivity);
222f19cb1f3facdb9f90ef1b26537ff303eaa3db77dAdam Powell    }
223bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
224bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
225bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    /**
226bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * Make an Intent for the main activity of an application, without
227bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * specifying a specific activity to run but giving a selector to find
228bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * the activity.  This results in a final Intent that is structured
229bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * the same as when the application is launched from
230bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * Home.  For anything else that wants to launch an application in the
231bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * same way, it is important that they use an Intent structured the same
232bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * way, and can use this function to ensure this is the case.
233bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     *
234bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * <p>The returned Intent has {@link Intent#ACTION_MAIN} as its action, and includes the
235bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * category {@link Intent#CATEGORY_LAUNCHER}.  This does <em>not</em> have
236bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * {@link Intent#FLAG_ACTIVITY_NEW_TASK} set, though typically you will want
237bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * to do that through {@link Intent#addFlags(int)} on the returned Intent.
238bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     *
239bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @param selectorAction The action name of the Intent's selector.
240bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @param selectorCategory The name of a category to add to the Intent's
241bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * selector.
242bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @return Returns a newly created Intent that can be used to launch the
243bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * activity as a main application entry.
244bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     *
245bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @see #setSelector(Intent)
246bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     */
247bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    public static Intent makeMainSelectorActivity(String selectorAction,
248bea2fc73637a1d59eb5face20006a27df6893042Adam Powell            String selectorCategory) {
249bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        return IMPL.makeMainSelectorActivity(selectorAction, selectorCategory);
250bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    }
251bea2fc73637a1d59eb5face20006a27df6893042Adam Powell
252bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    /**
253bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * Make an Intent that can be used to re-launch an application's task
254bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * in its base state.  This is like {@link #makeMainActivity(ComponentName)},
255bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * but also sets the flags {@link Intent#FLAG_ACTIVITY_NEW_TASK} and
256bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * {@link IntentCompat#FLAG_ACTIVITY_CLEAR_TASK}.
257bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     *
258bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @param mainActivity The activity component that is the root of the
259bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * task; this is the activity that has been published in the application's
260bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * manifest as the main launcher icon.
261bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     *
262bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * @return Returns a newly created Intent that can be used to relaunch the
263bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     * activity's task in its root state.
264bea2fc73637a1d59eb5face20006a27df6893042Adam Powell     */
265bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    public static Intent makeRestartActivityTask(ComponentName mainActivity) {
266bea2fc73637a1d59eb5face20006a27df6893042Adam Powell        return IMPL.makeRestartActivityTask(mainActivity);
267bea2fc73637a1d59eb5face20006a27df6893042Adam Powell    }
2681935ed3af7c6545bc38adfdc6026d87a3249222fSvetoslav Ganov}
269