BluetoothOppLauncherActivity.java revision d6641e4a7bb22833e1c07cb3af7989835fa7e16d
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 55 @Override 56 public void onCreate(Bundle savedInstanceState) { 57 super.onCreate(savedInstanceState); 58 59 Intent intent = getIntent(); 60 String action = intent.getAction(); 61 62 if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { 63 /* 64 * Other application is trying to share a file via Bluetooth, 65 * probably Pictures, videos, or vCards. The Intent should contain 66 * an EXTRA_STREAM with the data to attach. 67 */ 68 if (action.equals(Intent.ACTION_SEND)) { 69 // TODO(Moto): handle type == null case 70 String type = intent.getType(); 71 Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); 72 if (stream != null && type != null) { 73 if (Constants.LOGVV) { 74 Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = " 75 + type); 76 } 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 (Constants.LOGVV) { 92 Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= " 93 + mimeType); 94 } 95 BluetoothOppManager.getInstance(this).saveSendingFileInfo(mimeType, uris); 96 } else { 97 Log.e(TAG, "type is null; or sending files URIs are null"); 98 finish(); 99 return; 100 } 101 } 102 103 if (isAirplaneModeOn()) { 104 Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); 105 in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 106 in.putExtra("title", this.getString(R.string.airplane_error_title)); 107 in.putExtra("content", this.getString(R.string.airplane_error_msg)); 108 this.startActivity(in); 109 110 finish(); 111 return; 112 } 113 114 // TODO(Moto): In the future, we may send intent to DevicePickerActivity 115 // directly, 116 // and let DevicePickerActivity to handle Bluetooth Enable. 117 if (!BluetoothOppManager.getInstance(this).isEnabled()) { 118 if (Constants.LOGVV) { 119 Log.v(TAG, "Prepare Enable BT!! "); 120 } 121 Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); 122 in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 123 this.startActivity(in); 124 } else { 125 if (Constants.LOGVV) { 126 Log.v(TAG, "BT already enabled!! "); 127 } 128 Intent in1 = new Intent(BluetoothIntent.DEVICE_PICKER_DEVICE_PICKER); 129 in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 130 //TODO modify to false after SDP query is ok 131 in1.putExtra(BluetoothIntent.DEVICE_PICKER_NEED_AUTH, true); 132 in1.putExtra(BluetoothIntent.DEVICE_PICKER_FILTER_TYPE, 133 BluetoothDevice.DEVICE_PICKER_FILTER_TYPE_TRANSFER); 134 in1.putExtra(BluetoothIntent.DEVICE_PICKER_LAUNCH_PACKAGE, 135 Constants.THIS_PACKAGE_NAME); 136 in1.putExtra(BluetoothIntent.DEVICE_PICKER_LAUNCH_CLASS, 137 BluetoothOppReceiver.class.getName()); 138 139 this.startActivity(in1); 140 } 141 } else if (action.equals(Constants.ACTION_OPEN)) { 142 Uri uri = getIntent().getData(); 143 if (Constants.LOGVV) { 144 Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); 145 } 146 147 Intent intent1 = new Intent(); 148 intent1.setAction(action); 149 intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); 150 intent1.setData(uri); 151 this.sendBroadcast(intent1); 152 } 153 finish(); 154 } 155 156 /* Returns true if airplane mode is currently on */ 157 private final boolean isAirplaneModeOn() { 158 return Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 159 0) == 1; 160 } 161} 162