BluetoothOppLauncherActivity.java revision ce4d93666275df294cb073fe41de5b85932570a8
1/* 2 * Copyright (c) 2008-2009, Motorola, Inc. 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * - Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Motorola, Inc. nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33package com.android.bluetooth.opp; 34 35import com.android.bluetooth.R; 36 37import java.util.ArrayList; 38import android.app.Activity; 39import android.bluetooth.BluetoothDevice; 40import android.bluetooth.BluetoothIntent; 41import android.content.Intent; 42import android.net.Uri; 43import android.os.Bundle; 44import android.util.Log; 45import android.provider.Settings; 46 47/** 48 * This class is designed to act as the entry point of handling the share intent 49 * via BT from other APPs. and also make "Bluetooth" available in sharing method 50 * selection dialog. 51 */ 52public class BluetoothOppLauncherActivity extends Activity { 53 private static final String TAG = "BluetoothLauncherActivity"; 54 private static final boolean D = Constants.DEBUG; 55 private static final boolean V = Constants.VERBOSE; 56 57 @Override 58 public void onCreate(Bundle savedInstanceState) { 59 super.onCreate(savedInstanceState); 60 61 Intent intent = getIntent(); 62 String action = intent.getAction(); 63 64 if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { 65 /* 66 * Other application is trying to share a file via Bluetooth, 67 * probably Pictures, videos, or vCards. The Intent should contain 68 * an EXTRA_STREAM with the data to attach. 69 */ 70 if (action.equals(Intent.ACTION_SEND)) { 71 // TODO(Moto): handle type == null case 72 String type = intent.getType(); 73 Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); 74 if (stream != null && type != null) { 75 if (V) Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = " 76 + type); 77 // Save type/stream, will be used when adding transfer 78 // session to DB. 79 BluetoothOppManager.getInstance(this).saveSendingFileInfo(type, 80 stream.toString()); 81 } else { 82 Log.e(TAG, "type is null; or sending file URI is null"); 83 finish(); 84 return; 85 } 86 } else if (action.equals(Intent.ACTION_SEND_MULTIPLE)) { 87 ArrayList<Uri> uris = new ArrayList<Uri>(); 88 String mimeType = intent.getType(); 89 uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); 90 if (mimeType != null && uris != null) { 91 if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= " 92 + mimeType); 93 BluetoothOppManager.getInstance(this).saveSendingFileInfo(mimeType, uris); 94 } else { 95 Log.e(TAG, "type is null; or sending files URIs are null"); 96 finish(); 97 return; 98 } 99 } 100 101 if (isAirplaneModeOn()) { 102 Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); 103 in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 104 in.putExtra("title", this.getString(R.string.airplane_error_title)); 105 in.putExtra("content", this.getString(R.string.airplane_error_msg)); 106 this.startActivity(in); 107 108 finish(); 109 return; 110 } 111 112 // TODO(Moto): In the future, we may send intent to DevicePickerActivity 113 // directly, 114 // and let DevicePickerActivity to handle Bluetooth Enable. 115 if (!BluetoothOppManager.getInstance(this).isEnabled()) { 116 if (V) Log.v(TAG, "Prepare Enable BT!! "); 117 Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); 118 in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 119 this.startActivity(in); 120 } else { 121 if (V) Log.v(TAG, "BT already enabled!! "); 122 Intent in1 = new Intent(BluetoothIntent.DEVICE_PICKER_DEVICE_PICKER); 123 in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 124 //TODO modify to false after SDP query is ok 125 in1.putExtra(BluetoothIntent.DEVICE_PICKER_NEED_AUTH, true); 126 in1.putExtra(BluetoothIntent.DEVICE_PICKER_FILTER_TYPE, 127 BluetoothDevice.DEVICE_PICKER_FILTER_TYPE_TRANSFER); 128 in1.putExtra(BluetoothIntent.DEVICE_PICKER_LAUNCH_PACKAGE, 129 Constants.THIS_PACKAGE_NAME); 130 in1.putExtra(BluetoothIntent.DEVICE_PICKER_LAUNCH_CLASS, 131 BluetoothOppReceiver.class.getName()); 132 133 this.startActivity(in1); 134 } 135 } else if (action.equals(Constants.ACTION_OPEN)) { 136 Uri uri = getIntent().getData(); 137 if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); 138 139 Intent intent1 = new Intent(); 140 intent1.setAction(action); 141 intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); 142 intent1.setData(uri); 143 this.sendBroadcast(intent1); 144 } 145 finish(); 146 } 147 148 /* Returns true if airplane mode is currently on */ 149 private final boolean isAirplaneModeOn() { 150 return Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 151 0) == 1; 152 } 153} 154