BluetoothOppLauncherActivity分析

/**
 * 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中处理各种情况。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值