I am try to retrieve all images from phone in to a list format. so for that i first try to retrieve images in Content Provider.
But i am facing problem with that. my error is,
1. Method toURI() is undefined for the type Uri.
code:- ContentURI uri1 = new
ContentURI(android.provider.MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.toURI());
2. The method getColumnIndex(String)from the type cursor is Deprecated.
code:- int imageIndex =
cur.getColumnIndex(android.provider.MediaStore.Images.Media.DATA);
My Full Code is,
Using java Syntax Highlighting
- public class ImageCursor extends Activity {
- /** Called when the activity is first created. */
- public void onCreate(Bundle icicle) {
- final String TAG2 = "TAG2";
- Log.v(TAG2, "Start" );
- getDataImage();
- super.onCreate(icicle);
- }
- public void addImageB(){
- final String tag="aaaa";
- Log.i(tag,"TO ADD");
- ContentValues values = new ContentValues();
- values.put(android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, "road_trip_1");
- values.put(android.provider.MediaStore.Images.ImageColumns.DESCRIPTION, "Day 1 trip to Los Angeles");
- Uri uri =
- getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
- OutputStream outStream;
- try {
- outStream = getContentResolver().openOutputStream(uri);
- Bitmap sourceBitmap =
- BitmapFactory.decodeResource(this.getResources(),
- R.drawable.icon);
- sourceBitmap.compress(Bitmap.CompressFormat.PNG, 50, outStream);
- outStream.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- Log.i(tag, e.getMessage());
- } catch (IOException e) {
- e.printStackTrace();
- Log.i(tag, e.getMessage());
- }
- }
- public void getDataImage(){
- // ############# PROBLEM HERE #############
- ContentURI uri1 = new
- ContentURI(android.provider.MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.toURI());
- // ############# END PROBLEM #############
- Cursor cur = this.managedQuery(uri1, projection, null, null);
- final String tag2="aaaa";
- Log.i(tag2,"NUM");
- if(cur != null)
- getColumnDataImage(cur);
- }
- private void getColumnDataImage(Cursor cur){
- // if(!cur.first())
- // return;
- cur.moveToFirst();
- int imageIndex =
- cur.getColumnIndex(android.provider.MediaStore.Images.Media.DATA);
- if(imageIndex==0)
- {
- final String tag2="aaa";
- Log.i(tag2,"No files are there");
- }
- else
- {
- final String tag2="aaaa";
- Log.i(tag2,"files ");
- }
- /* do {
- ContentURI imagePath = null;
- String u = cur.getString(imageIndex);
- Log.i("MYAPP>>>>", ""+u);
- if(u!=null){
- try {
- imagePath = new ContentURI(u);
- } catch (URISyntaxException e) {
- e.printStackTrace();
- Log.e("MYAPP>>>>", e.getMessage());
- }
- Log.i("MYAPP>>>>", ""+imagePath.toString());
- if(imagePath != null){
- InputStream is = null;
- ContentResolver cr = this.getContentResolver();
- if(cr != null){
- try{
- is = cr.openInputStream(imagePath);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- Log.e("MYAPP>>>>", e.getMessage());
- }
- }
- if(is != null){
- b = BitmapFactory.decodeStream(is);
- }
- }
- }
- }while (cur.next());*/
- }
- }
Parsed in 0.046 seconds, using GeSHi 1.0.8.4
Please Do help as soon as possible..its too urgent.



