code for retrieving files from phone memory

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

code for retrieving files from phone memory

Postby pushpa » Mon Jun 29, 2009 7:58 am

hi,
can anyone help me with a source code(android 1.5)for retrieving files from phone memory(android emulator)



Thank you
pushpa
pushpa
Freshman
Freshman
 
Posts: 9
Joined: Tue Jun 09, 2009 10:37 am

Top

Postby pinaise » Sun Jul 05, 2009 7:40 pm

You can do this by sending an intent for the image gallery.
first fire the intent:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3. Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
  4.  
  5. startActivityForResult(i, 1);
  6.  
  7.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

with this code you fire an intent to open the imagegallery.
and you start the activity to get a result (your image)

After this you got to capture the result (the selected image) from the imagegallery:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. //implement the onActivity for result method
  3.  
  4.         protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  5.  
  6.                 super.onActivityResult(requestCode, resultCode, intent);
  7.  
  8.  
  9.  
  10.                         if(resultCode == RESULT_OK){  
  11.  
  12.  
  13.  
  14.                             Uri selectedImage = intent.getData();  
  15.  
  16.                             String [] proj={MediaStore.Images.Media.DATA};
  17.  
  18.  
  19.  
  20.                             Cursor cursor = managedQuery(selectedImage,proj,null,null,null);  
  21.  
  22.                             int column_index = cursor.getColumnIndexOrThrow(proj[0]);
  23.  
  24.                             cursor.moveToNext();
  25.  
  26.                             String filePath = cursor.getString(column_index);
  27.  
  28.                             bitmap = BitmapFactory.decodeFile(filePath);
  29.  
  30.  //bitmap = youre image
  31.  
  32.                         }
  33.  
  34.                         else if (resultCode == RESULT_CANCELED) {
  35.  
  36.                                
  37.  
  38.                         }
  39.  
  40.                 }
  41.  
  42.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
pinaise
Freshman
Freshman
 
Posts: 9
Joined: Sun Jul 05, 2009 7:00 pm

Postby minhzc » Sun Aug 02, 2009 6:02 pm

I have the same problem.
I have an ImageView and a Button
I want to click on a button and the "file browser" is open for browser image file. and then the ImageView will display the choosen image file.

So have I to add this to Button listener?
Code: Select all
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, 1);


and then, where to call the "protected void onActivityResult" ?
thanks you.
minhzc
Freshman
Freshman
 
Posts: 8
Joined: Sun Aug 02, 2009 10:26 am
Location: Vietnam

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests