Android reads the image instance on the sdcard (must see)

It is very easy for Android to read the pictures on the sdcard. Here is an example to illustrate this problem.

First, there is a ready img25.jpg on the sdcard

Next, what you need to do is read this picture into the app and display it. Achieve the following effects:

1. First, you should apply for permission to read sdcard in androidmanifest.xml. After adding a statement, androidmanifest.xml is as follows:

2. Then, in res \ values \ strings.xml, change the name of the app to "image reading". This step can be omitted, just to make the program more beautiful.

3. Secondly, in res \ layout \ activity_ A textview with ID will be arranged in main.xml, and the prompt information will be written into this textview. At the same time, a linear layout with ID will be arranged. The picture will be added to the linear layout later.

4. The core of the whole program is mainactivity.java. The code is as follows. After obtaining the components, first use environment. Getexternalstoragestate(). Equals (environment. Media_mounted); Determine whether the sdcard exists, and then use environment. Getexternalstoragedirectory(). Getabsolutepath(); Get the absolute path of sdcard for java file class to read. Finally, create an ImageView object and load it into linear layout linearlayout1.

The above example of Android reading pictures on sdcard (must see) is all the content shared by Xiaobian. I hope it can give you a reference and support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>