2017-03-09 22 views
1

我正在开发一些Android应用程序并使用常规相机(不是自定义相机)。该应用程序具有所有必要的权限(摄像头,写入和读取外部)。直到昨天一切正常:拍摄后,保存在设备库中的图像可以显示在ImageView。我升级到Android 7.0,现在相机不再保存图像,活动结果返回nulldata.getData())。保存图像不能正常工作,因为升级到android 7

有谁知道Android 7.0中有哪些变化?

+0

在你的类中使用'cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,picUri);' –

+0

好的显示你的代码,我会说。 – greenapps

+0

'现在相机不再保存图像'。相机不保存图像。只有相机应用程序可以这样做。你在用吗?您仍然可以用设备上的相机应用以正常方式拍照吗? – greenapps

回答

1
public class SaveImageAsync extends AsyncTask<Integer, Void, Void> { 
    @Override 
    protected Void doInBackground(Integer... params) { 


     try { 


      InputStream in; 
      BufferedInputStream buf; 
      int position = params[0]; 

      if (URLUtil.isNetworkUrl(use image here)) { 
       in = new URL(use image here 
       ).openStream(); 


       buf = new BufferedInputStream(in); 
       Bitmap _bitmapPreScale = BitmapFactory.decodeStream(buf); 
       int oldWidth = _bitmapPreScale.getWidth(); 
       int oldHeight = _bitmapPreScale.getHeight(); 
       int newWidth = 2592; 
       int newHeight = 1936; 

       float scaleWidth = ((float) newWidth)/oldWidth; 
       float scaleHeight = ((float) newHeight)/oldHeight; 

       Matrix matrix = new Matrix(); 

       matrix.postScale(scaleWidth, scaleHeight); 
       Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true); 


       ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
       _bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes); 

       File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"wave"); 
       directory.mkdirs(); 
       directory.mkdir(); 


       File f = new File(directory, "writeurnamefolder_Gallery" + System.currentTimeMillis() + ".jpg"); 


       f.createNewFile(); 

       FileOutputStream fo = new FileOutputStream(f); 
       fo.write(bytes.toByteArray()); 

       fo.close(); 
      } else if (URLUtil.isFileUrl(use here original image)) { 
       MediaStore.Images.Media.insertImage(getContentResolver(), Uri.parse(get your image here.getPath(), "writeurnamefolder_Gallery" + System.currentTimeMillis(), "Gallery Image :"); 
      } 

     } catch (IOException e) { 
      e.printStackTrace(); 

     } 

     return null; 
    } 


} 
+0

,你必须给予这些许可,我希望这将有助于你.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_CONTACTS –

+0

什么一堆不到点代码。没有人要求这样的代码。是什么让你这么想? – greenapps

0

文件://不允许再意图连接或将抛出FileUriExposedException这可能会导致您的应用程序崩溃立即调用。

相关问题