简体   繁体   English

未为类型MediaStore.Audio.Media android定义方法Media.getBitmap(ContentResolver,Uri)

[英]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. 如果这是问题,我的活动正在扩展MapsActivity。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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