相机功能在4.4版本设备android中无效

时间:2014-08-21 11:13:06

标签: android android-camera android-4.4-kitkat

在我的按钮中单击我打开相机如下:

private int REQUEST_CAMERA = 3;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                            
startActivityForResult(intent,REQUEST_CAMERA);

我的OnActivityResult方法代码如下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data);

         if (requestCode == REQUEST_CAMERA) {

            openGalleryImage(data);
            saveImage(uri_outputFileUri.getPath());
        } 
}

openGalleryImage方法:

private void openGalleryImage(Intent data) 
{
    Uri selectedimg = data.getData();
    Uri uriselectedimage=data.getData();
    mString=uriselectedimage.getPath();
    try 
    {
        mInputStream=getContentResolver().openInputStream(selectedimg);
    }
    catch (FileNotFoundException e) 
    {
        e.printStackTrace();
    }

    String[] path = { MediaStore.Images.Media.DATA };
    Cursor c = getContentResolver().query(selectedimg, path, null, null,null);
    c.moveToFirst();
    int columnIndex = c.getColumnIndex(path[0]);
    selectedimage_paths=c.getString(columnIndex);
    uri_outputFileUri= Uri.parse(selectedimage_paths);
    c.close();
}

saveImage方法:

private void saveImage(String mPath) 
{

    if (RentalApplicaiton.ISSDCARDPresent==true) {
        mediaDir= new File(Environment.getExternalStorageDirectory() +"/MyFolder");
        mediaDir.mkdir();
        submediaDir= new File(Environment.getExternalStorageDirectory() +"/MyFolder/TempFolder");
        submediaDir.mkdir();
    }
    else {
        mediaDir= new File(getCacheDir() ,"/MyFolder");
        mediaDir.mkdir();
        submediaDir= new File(getCacheDir() ,"/MyFolder/TempFolder");
        submediaDir.mkdir();
    }

    File myImage = new File(mediaDir, Long.toString(System.currentTimeMillis()) + ".png");
    File myImages = new File(submediaDir, Long.toString(System.currentTimeMillis()) + ".png");

    try 
    { 
        FileOutputStream out = new FileOutputStream(myImage);
        mbitmap_outputImage=BitmapFactory.decodeFile(mPath);    
        mbitmap_outputImage=Bitmap.createScaledBitmap(mbitmap_outputImage, 390, 310, true);
        mbitmap_outputImage.compress(Bitmap.CompressFormat.PNG, 100, out); 
        out.flush();    
        out.close();
        getimagesfromSdcard();
        mGallery.setAdapter(mImageCustomAdapter);

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

    try 
    { 
        FileOutputStream out = new FileOutputStream(myImages);
        mbitmap_outputImage=BitmapFactory.decodeFile(mPath);    
        mbitmap_outputImage=Bitmap.createScaledBitmap(mbitmap_outputImage, 390, 310, true);
        mbitmap_outputImage.compress(Bitmap.CompressFormat.PNG, 100, out); 
        out.flush();    
        out.close();
        getimagesfromSdcard();
        mGallery.setAdapter(mImageCustomAdapter);

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

}

当我运行此代码时,它在4.0到4.3设备上正常工作,该问题仅出现在4.4(Kitkat)设备上。当我在4.4设备上捕获照片时,它会直接强制关闭我的应用程序。知道怎么解决这个问题?

0 个答案:

没有答案