1

我正在使用这段代码:

private static final int TAKE_PHOTO_CODE = 1;  

private void takePhoto(){  
  final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) );   
  startActivityForResult(intent, TAKE_PHOTO_CODE);  
}  

private File getTempFile(Context context){  
  //it will return /sdcard/image.tmp  
  final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );  
  if(!path.exists()){  
    path.mkdir();  
  }  
  return new File(path, "image.tmp");  
}  

@Override  
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  if (resultCode == RESULT_OK) {  
    switch(requestCode){  
      case TAKE_PHOTO_CODE:  
        final File file = getTempFile(this);  
        try {  
          Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file) );  
          // do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc)  
        } catch (FileNotFoundException e) {  
          e.printStackTrace();  
        } catch (IOException e) {  
          e.printStackTrace();  
        }  
      break;  
    }  
  }  
}  

我收到了这个错误:

method Media.getBitmap(ContentResolver, Uri) is undefined for type MediaStore.Audio.Media

如果这是问题,我的活动正在扩展 MapsActivity。

你能帮助我吗?

4

1 回答 1

1

检查您已导入的类。猜你已经进口了

import android.provider.MediaStore.Audio.Media;

而是导入

import android.provider.MediaStore.Images.Media;
于 2013-02-16T11:08:03.660 回答