ChooserActivity.java revision 2c60de3f6d849a581cca89ece7149c3836b3b6e4
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        if (title == null) {
47            title = getResources().getText(com.android.internal.R.string.chooseActivity);
48        }
49        Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
50        Intent[] initialIntents = null;
51        if (pa != null) {
52            initialIntents = new Intent[pa.length];
53            for (int i=0; i<pa.length; i++) {
54                if (!(pa[i] instanceof Intent)) {
55                    Log.w("ChooserActivity", "Initial intent #" + i + " not an Intent: " + pa[i]);
56                    finish();
57                    super.onCreate(null);
58                    return;
59                }
60                final Intent in = (Intent) pa[i];
61                final String action = in.getAction();
62                if (Intent.ACTION_SEND.equals(action) ||
63                        Intent.ACTION_SEND_MULTIPLE.equals(action)) {
64                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
65                            Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
66                            Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
67                }
68                initialIntents[i] = in;
69            }
70        }
71        super.onCreate(savedInstanceState, target, title, initialIntents, null, false);
72    }
73}
74