Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android蓝牙文件共享流_Android_Bluetooth - Fatal编程技术网

Android蓝牙文件共享流

Android蓝牙文件共享流,android,bluetooth,Android,Bluetooth,嗨,我有这个方法,通过蓝牙发送文件工作得很好。我想知道我是否可以使用它来接收和播放它,就像通过蓝牙传输一样。换句话说,播放它而不是保存它 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode == DISCOVER_DURATION && requestCode == REQUEST_BLU) { Int

嗨,我有这个方法,通过蓝牙发送文件工作得很好。我想知道我是否可以使用它来接收和播放它,就像通过蓝牙传输一样。换句话说,播放它而不是保存它

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(resultCode == DISCOVER_DURATION && requestCode == REQUEST_BLU) {

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            File f = new File(Environment.getExternalStorageDirectory(), "one.mp3");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));

            PackageManager pm = getPackageManager();
            List<ResolveInfo> appsList = pm.queryIntentActivities(intent, 0);

            if(appsList.size() > 0) {
                String packageName = null;
                String className = null;
                boolean found = false;

                for(ResolveInfo info : appsList) {
                    packageName = info.activityInfo.packageName;
                    if(packageName.equals("com.android.bluetooth")) {
                        className = info.activityInfo.name;
                        found = true;
                        break;
                    }
                }

                if (!found) {
                    Toast.makeText(this, "Bluetooth havn't been found",
                            Toast.LENGTH_LONG).show();
                } else {
                    intent.setClassName(packageName, className);
                    startActivity(intent);
                }
            }
        } else {
            Toast.makeText(this, "Bluetooth is cancelled", Toast.LENGTH_LONG)
                    .show();
        }
    }
activityresult上受保护的void(int-requestCode、int-resultCode、Intent-data){
if(resultCode==DISCOVER\u DURATION&&requestCode==REQUEST\u BLU){
意图=新意图();
intent.setAction(intent.ACTION\u SEND);
intent.setType(“文本/普通”);
文件f=新文件(Environment.getExternalStorageDirectory(),“one.mp3”);
intent.putExtra(intent.EXTRA_流,Uri.fromFile(f));
PackageManager pm=getPackageManager();
List-appsList=pm.querytentActivities(intent,0);
如果(appsList.size()>0){
字符串packageName=null;
字符串className=null;
布尔值=false;
用于(ResolveInfo:appsList){
packageName=info.activityInfo.packageName;
if(packageName.equals(“com.android.bluetooth”)){
className=info.activityInfo.name;
发现=真;
打破
}
}
如果(!找到){
Toast.makeText(此“蓝牙尚未找到”,
Toast.LENGTH_LONG).show();
}否则{
intent.setClassName(packageName,className);
星触觉(意向);
}
}
}否则{
Toast.makeText(此“蓝牙已取消”,Toast.LENGTH\u LONG)
.show();
}
}