/**
* This class is designed to act as the entry point of handling the share intent
* via BT from other APPs. and also make "Bluetooth" available in sharing method
* selection dialog.
*/
该Activity是其他activity通过蓝牙来共享(或者叫发送)文件的接口。
Intent intent = getIntent();//获取Intent
String action = intent.getAction();//获取Intent的内容
if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) {
首先判断操作类型:是发送单个文件,多个文件,还是打开文件。
Intent.ACTION_SEND
Intent.ACTION_SEND_MULTIPLE
Constants.ACTION_OPEN
其中Intent.ACTION_SEND分成两种情况:
1) If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the uri data;
2) If we get ACTION_SEND intent without EXTRA_STREAM, but with EXTRA_TEXT,
we will try send this TEXT out; Currently in Browser, share one link goes to this case;
对于这种情况会调用creatFileForSharedContent来创建文件的url。
而对于ACTION_SEND intent with EXTRA_STREAM以及ACTION_SEND_MULTIPLE,会启动一个thread来存储这些信息,
之后还要选择发送到哪一个设备。
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();
}
});
launchDevicePicker指定了如何选择设备。
对于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.setDataAndNormalize(uri);
this.sendBroadcast(intent1);
finish();
主要是发送广播给BluetoothOppReceiver,在BluetoothOppReceiver中处理各种情况。