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