Loading android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +87 −48 Original line number Diff line number Diff line Loading @@ -69,6 +69,17 @@ public class BluetoothOppLauncherActivity extends Activity { String action = intent.getAction(); if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { //Check if Bluetooth is available in the beginning instead of at the end if (!isBluetoothAllowed()) { Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.putExtra("title", this.getString(R.string.airplane_error_title)); in.putExtra("content", this.getString(R.string.airplane_error_msg)); startActivity(in); finish(); return; } /* * Other application is trying to share a file via Bluetooth, * probably Pictures, videos, or vCards. The Intent should contain Loading @@ -76,8 +87,8 @@ public class BluetoothOppLauncherActivity extends Activity { */ if (action.equals(Intent.ACTION_SEND)) { // TODO: handle type == null case String type = intent.getType(); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); final String type = intent.getType(); final Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // uri data; Loading @@ -89,16 +100,38 @@ public class BluetoothOppLauncherActivity extends Activity { + type); // Save type/stream, will be used when adding transfer // session to DB. BluetoothOppManager.getInstance(this).saveSendingFileInfo(type, stream.toString(), false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(type,stream.toString(), false); //Done getting file info..Launch device picker and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else if (extra_text != null && type != null) { if (V) Log.v(TAG, "Get ACTION_SEND intent with Extra_text = " + extra_text.toString() + "; mimetype = " + type); Uri fileUri = creatFileForSharedContent(this, extra_text); final Uri fileUri = creatFileForSharedContent(this, extra_text); if (fileUri != null) { BluetoothOppManager.getInstance(this).saveSendingFileInfo(type, fileUri.toString(), false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(type,fileUri.toString(), false); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else { Log.w(TAG,"Error trying to do set text...File not created!"); finish(); return; } } else { Log.e(TAG, "type is null; or sending file URI is null"); Loading @@ -106,32 +139,50 @@ public class BluetoothOppLauncherActivity extends Activity { return; } } else if (action.equals(Intent.ACTION_SEND_MULTIPLE)) { ArrayList<Uri> uris = new ArrayList<Uri>(); String mimeType = intent.getType(); uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); final String mimeType = intent.getType(); final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (mimeType != null && uris != null) { if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= " + mimeType); BluetoothOppManager.getInstance(this).saveSendingFileInfo(mimeType, uris, false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(mimeType,uris, false); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else { Log.e(TAG, "type is null; or sending files URIs are null"); finish(); return; } } } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); if (!isBluetoothAllowed()) { Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.putExtra("title", this.getString(R.string.airplane_error_title)); in.putExtra("content", this.getString(R.string.airplane_error_msg)); this.startActivity(in); Intent intent1 = new Intent(); intent1.setAction(action); intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); intent1.setData(uri); this.sendBroadcast(intent1); finish(); return; } else { Log.w(TAG, "Unsupported action: " + action); finish(); } } /** * Turns on Bluetooth if not already on, or launches device picker if Bluetooth is on * @return */ private final void launchDevicePicker() { // TODO: In the future, we may send intent to DevicePickerActivity // directly, // and let DevicePickerActivity to handle Bluetooth Enable. Loading @@ -139,7 +190,7 @@ public class BluetoothOppLauncherActivity extends Activity { if (V) Log.v(TAG, "Prepare Enable BT!! "); Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(in); startActivity(in); } else { if (V) Log.v(TAG, "BT already enabled!! "); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); Loading @@ -152,21 +203,9 @@ public class BluetoothOppLauncherActivity extends Activity { in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS, BluetoothOppReceiver.class.getName()); if (V) {Log.d(TAG,"Launching " +BluetoothDevicePicker.ACTION_LAUNCH );} this.startActivity(in1); startActivity(in1); } } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); Intent intent1 = new Intent(); intent1.setAction(action); intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); intent1.setData(uri); this.sendBroadcast(intent1); } finish(); } /* Returns true if Bluetooth is allowed given current airplane mode settings. */ private final boolean isBluetoothAllowed() { final ContentResolver resolver = this.getContentResolver(); Loading Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +87 −48 Original line number Diff line number Diff line Loading @@ -69,6 +69,17 @@ public class BluetoothOppLauncherActivity extends Activity { String action = intent.getAction(); if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { //Check if Bluetooth is available in the beginning instead of at the end if (!isBluetoothAllowed()) { Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.putExtra("title", this.getString(R.string.airplane_error_title)); in.putExtra("content", this.getString(R.string.airplane_error_msg)); startActivity(in); finish(); return; } /* * Other application is trying to share a file via Bluetooth, * probably Pictures, videos, or vCards. The Intent should contain Loading @@ -76,8 +87,8 @@ public class BluetoothOppLauncherActivity extends Activity { */ if (action.equals(Intent.ACTION_SEND)) { // TODO: handle type == null case String type = intent.getType(); Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); final String type = intent.getType(); final Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // uri data; Loading @@ -89,16 +100,38 @@ public class BluetoothOppLauncherActivity extends Activity { + type); // Save type/stream, will be used when adding transfer // session to DB. BluetoothOppManager.getInstance(this).saveSendingFileInfo(type, stream.toString(), false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(type,stream.toString(), false); //Done getting file info..Launch device picker and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else if (extra_text != null && type != null) { if (V) Log.v(TAG, "Get ACTION_SEND intent with Extra_text = " + extra_text.toString() + "; mimetype = " + type); Uri fileUri = creatFileForSharedContent(this, extra_text); final Uri fileUri = creatFileForSharedContent(this, extra_text); if (fileUri != null) { BluetoothOppManager.getInstance(this).saveSendingFileInfo(type, fileUri.toString(), false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(type,fileUri.toString(), false); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else { Log.w(TAG,"Error trying to do set text...File not created!"); finish(); return; } } else { Log.e(TAG, "type is null; or sending file URI is null"); Loading @@ -106,32 +139,50 @@ public class BluetoothOppLauncherActivity extends Activity { return; } } else if (action.equals(Intent.ACTION_SEND_MULTIPLE)) { ArrayList<Uri> uris = new ArrayList<Uri>(); String mimeType = intent.getType(); uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); final String mimeType = intent.getType(); final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (mimeType != null && uris != null) { if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= " + mimeType); BluetoothOppManager.getInstance(this).saveSendingFileInfo(mimeType, uris, false); Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(mimeType,uris, false); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else { Log.e(TAG, "type is null; or sending files URIs are null"); finish(); return; } } } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); if (!isBluetoothAllowed()) { Intent in = new Intent(this, BluetoothOppBtErrorActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.putExtra("title", this.getString(R.string.airplane_error_title)); in.putExtra("content", this.getString(R.string.airplane_error_msg)); this.startActivity(in); Intent intent1 = new Intent(); intent1.setAction(action); intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); intent1.setData(uri); this.sendBroadcast(intent1); finish(); return; } else { Log.w(TAG, "Unsupported action: " + action); finish(); } } /** * Turns on Bluetooth if not already on, or launches device picker if Bluetooth is on * @return */ private final void launchDevicePicker() { // TODO: In the future, we may send intent to DevicePickerActivity // directly, // and let DevicePickerActivity to handle Bluetooth Enable. Loading @@ -139,7 +190,7 @@ public class BluetoothOppLauncherActivity extends Activity { if (V) Log.v(TAG, "Prepare Enable BT!! "); Intent in = new Intent(this, BluetoothOppBtEnableActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(in); startActivity(in); } else { if (V) Log.v(TAG, "BT already enabled!! "); Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); Loading @@ -152,21 +203,9 @@ public class BluetoothOppLauncherActivity extends Activity { in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS, BluetoothOppReceiver.class.getName()); if (V) {Log.d(TAG,"Launching " +BluetoothDevicePicker.ACTION_LAUNCH );} this.startActivity(in1); startActivity(in1); } } else if (action.equals(Constants.ACTION_OPEN)) { Uri uri = getIntent().getData(); if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri); Intent intent1 = new Intent(); intent1.setAction(action); intent1.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); intent1.setData(uri); this.sendBroadcast(intent1); } finish(); } /* Returns true if Bluetooth is allowed given current airplane mode settings. */ private final boolean isBluetoothAllowed() { final ContentResolver resolver = this.getContentResolver(); Loading