Android 調用系統藍牙發送文件

 調用原生系統的文件分享中的藍牙分享功能

 //調用android分享窗口
                Intent intent2 = new Intent(Intent.ACTION_SEND);
                intent2.setType("*/*");
                intent2.setPackage("com.android.bluetooth");
                intent2.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath() + "//" + "盤點導入//"  + fileName)));//path爲文件的路徑
                intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//7.0以上可能會報錯  java.lang.SecurityException: Permission Denial
//使用這一段即可
                StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
                StrictMode.setVmPolicy(builder.build());
                builder.detectFileUriExposure();

                Intent chooser = Intent.createChooser(intent2, "Share app");
                chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(Intent.createChooser(chooser, "分享"));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章