The Android development ImageView image cannot show the resolution process

  • 2020-05-10 18:48:22
  • OfStack

Today I came across a very strange question:
ImageView cannot display the loaded local SDCard image in Android.
The process is as follows: the local camera program is first called to record, and then the pictures taken are loaded into ImageView for display.
 
public class ActiEnvi extends Activity { 
static final String TAG = "ActiEnvi"; 
private static final int REQ_CODE_CAMERA = 0x1; 

private String imgpath = ""; 
private String tempath = ""; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.acti_envi); 

...... 
} 
...... 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
//  Photo taken and returned  
if (requestCode == REQ_CODE_CAMERA 
&& resultCode == Activity.RESULT_OK) { 
this.imgpath = tempath; 
Bitmap bm = BitmapFactory.decodeFile(this.imgpath); 
imgView.setImageBitmap(bm); 
imgView.setScaleType(ScaleType.FIT_CENTER); 
} 
} 

....... 
//  Call the system camera to take pictures  
protected void captureImage() { 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
tempath = IOHelper.generateImgPath(); 
File out = new File(tempath); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out)); 
startActivityForResult(intent, REQ_CODE_CAMERA); 
} 
...... 
} 

It feels like a weird question. I remember that I did a project before, which was loaded with pictures. After the comparison, I found that there was no problem with the code logic and layout. What was the problem?

Internet search for a long time, no results, feeling mad to the edge... When I was about to give up, I accidentally compared the AndroidManifest.xml file and found a slight difference. The difference was android in users-sdk :targetSdkVersion has and has not. So I changed.
 
<uses-sdk android:minSdkVersion="8" /> 
<!-- android:targetSdkVersion="17" --> 

I noticed that I commented out android:targetSdkVersion in users-sdk, and when I was debugging, the image was displayed. Why is that?? Suddenly speechless, for god to explain ah...

Related articles: