简体   繁体   中英

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

I am using this code:

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;  
    }  
  }  
}  

and I am getting this error:

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

My activity is extending MapsActivity if this is the problem.

Can you help me?

Check the class which you have imported. Guess u have imported

import android.provider.MediaStore.Audio.Media;

Instead import

import android.provider.MediaStore.Images.Media;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM