- Contact Number
- Media Storage (audio, videos, and images)
- Browser bookmarks.
That all are built in content providers. We develop own content provider to extend the base class of content providers.
Now we used content provider to access built-in Contents
Fist of all we want to access all all images of Phone which are stored in Sd card.
private String TAG=”android.imges”;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri Images=Uri.parse(“android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI”);
Cursor cursor = managedQuery(Images, null, null, null, null);
// All images path
while (cursor.moveToNext()) {
String path= cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
log.d(TAG, path);
}
- First There are used built-in Uri to access shared contents . some are given below to access desired contents
we used the image Uri to access it. you can use any of the following
- Browser.BOOKMARKS_URI
- Browser.SEARCHES_URI
- CallLog.CONTENT_URI
- MediaStore.Images.Media.INTERNAL_CONTENT_URI
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI
- Settings.CONTENT_URI
- Second we discuss managQuery method which return Cursor object . cursor object contain all retrieved data. and we can easily navigate in cursor object to retrieve all are specific record.
- Third we now retrieve path of every images from cursor object using while loop and diplay in LogCat .
The above code display the path of every image which are stored in android phone sd card. Now we can develop gallery , image switcher and others application where we required all images of internal storage or external storage.