ChooserActivity.java revision 278902c982443b3c196aa4642dcf3e0fffe4b23d
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.app;
18
19import android.content.Intent;
20import android.os.Bundle;
21import android.os.Parcelable;
22import android.util.Log;
23
24public class ChooserActivity extends ResolverActivity {
25    @Override
26    protected void onCreate(Bundle savedInstanceState) {
27        Intent intent = getIntent();
28        Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
29        if (!(targetParcelable instanceof Intent)) {
30            Log.w("ChooserActivity", "Target is not an intent: " + targetParcelable);
31            finish();
32            super.onCreate(null);
33            return;
34        }
35        Intent target = (Intent)targetParcelable;
36        if (target != null) {
37            final String action = target.getAction();
38            if (Intent.ACTION_SEND.equals(action) ||
39                    Intent.ACTION_SEND_MULTIPLE.equals(action)) {
40                target.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
41                        Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
42                        Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
43            }
44        }
45        CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
46        int defaultTitleRes = 0;
47        if (title == null) {
48            defaultTitleRes = com.android.internal.R.string.chooseActivity;
49        }
50        Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
51        Intent[] initialIntents = null;
52        if (pa != null) {
53            initialIntents = new Intent[pa.length];
54            for (int i=0; i<pa.length; i++) {
55                if (!(pa[i] instanceof Intent)) {
56                    Log.w("ChooserActivity", "Initial intent #" + i + " not an Intent: " + pa[i]);
57                    finish();
58                    super.onCreate(null);
59                    return;
60                }
61                final Intent in = (Intent) pa[i];
62                final String action = in.getAction();
63                if (Intent.ACTION_SEND.equals(action) ||
64                        Intent.ACTION_SEND_MULTIPLE.equals(action)) {
65                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
66                            Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
67                            Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
68                }
69                initialIntents[i] = in;
70            }
71        }
72        super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
73                null, false);
74    }
75}
76