public static int SavePhoto(String filePath, String fileNmae) { if (ActivityCompat.checkSelfPermission(AndroidPlugin.instance, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String[] mPermissionList = new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE, }; if (ActivityCompat.shouldShowRequestPermissionRationale(AndroidPlugin.instance, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { ActivityCompat.requestPermissions(instance, mPermissionList, SdkConst.req_code_permission_writestorage); return 2;//忽略 } else { ActivityCompat.requestPermissions(instance, mPermissionList, SdkConst.req_code_permission_writestorage); return 0; } } } instance.runOnUiThread(new Runnable() { public void run() { Bitmap bitmap = BitmapFactory.decodeFile(filePath); File file = new File(Environment.getExternalStorageDirectory() + "/Pictures", fileNmae); FileOutputStream fos = null; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Log.w("unity", e.toString()); } bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); try { fos.flush(); } catch (IOException e) { // TODO Auto-generated catch block Log.w("cat", e.toString()); } try { fos.close(); } catch (IOException e) { // TODO Auto-generated catch block Log.w("cat", e.toString()); } bitmap.recycle();//扫描保存的图片 instance.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/Pictures/" + fileNmae))); } }); return 1; }