An android we used File , Data Base for Stored data permanently. These file and Database are accessible only to its application . Others application and packages can not access this. There fore android provide Content Provider to shared data among packages and application. Some android shared contents are following
- Contact Number
- Media Storage (audio, videos, and images)
- Browser bookmarks.
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.
public class MainActivity extends Activity {
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);
}
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
- 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 .
0 Comments