accessing phone images through content provider

All your problems with Audio, Video and Images.

accessing phone images through content provider

Postby tabman » Sat May 22, 2010 9:42 pm

Hi,

I need a sample code or tutorial for accessing phone images/media through content provider ?

I know the following, what next ?

ContentResolver cr = mContext.getContentResolver(); Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
tabman
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat May 22, 2010 9:38 pm

Top

Re: accessing phone images through content provider

Postby stece » Tue May 25, 2010 9:07 am

hello tabman

could be a stupid question, but why do you want to use the content provider?

I always use

Code: Select all
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent,   "Select Picture"), 1);

Code: Select all

   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      
      Uri selectedImage = data.getData ();
                String realPath = getRealPathFromURI(selectedImage);

   }
   
    public String getRealPathFromURI(Uri contentUri) { 
      
        String [] proj={MediaStore.Images.Media.DATA}; 
        Cursor cursor = managedQuery( contentUri, 
                proj, // Which columns to return 
                null,       // WHERE clause; which rows to return (all rows) 
                null,       // WHERE clause selection arguments (none) 
                null); // Order-by clause (ascending by name) 
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
        cursor.moveToFirst(); 
      
        return cursor.getString(column_index); 
    } 

User avatar
stece
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Wed Apr 21, 2010 10:50 am
Location: Belgium

Re: accessing phone images through content provider

Postby tabman » Tue May 25, 2010 12:33 pm

I found what I was looking for here:
http://androidsamples.blogspot.com/2009 ... mages.html
tabman
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat May 22, 2010 9:38 pm

Re: accessing phone images through content provider

Postby tabman » Sat Jun 05, 2010 11:15 pm

So following the previous question I want to get the images in sorted order according to when they were taken, how can I do that. The following doesn't work:

imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, columns, null,null, MediaStore.Images.ImageColumns.DATE_TAKEN+"");
tabman
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat May 22, 2010 9:38 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 25 guests