Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3164] Android: Expose MediaScannerConnection

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:01:05.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-11
ComponentsAndroid
Labelsandroid, feature, release-1.7.0, rplist
ReporterDawson Toth
AssigneeDon Thorp
Created2011-04-15T03:38:28.000+0000
Updated2011-04-17T02:01:05.000+0000

Description

Problem

When you save an image to the SDCard, the media scanner won't pick it up until the next time it runs (when the phone restarts).

Solution

Exposing the MediaScannerConnection would let developers get the image into the gallery right away.

Android Documentation

http://developer.android.com/reference/android/media/MediaScannerConnection.html"> http://developer.android.com/reference/android/media/MediaScannerCo...

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/69031">http://developer.appcelerator.com/helpdesk/view/69031

Attachments

FileDateSize
fj.jpg2011-04-15T03:38:29.000+0000114242

Comments

  1. Bill Dawson 2011-04-15

    (from [8e7685715cea203abbe9df1c9e2f42f6aafe3e0a]) Doc for scanMediaFiles [#3164] https://github.com/appcelerator/titanium_mobile/commit/8e7685715cea203abbe9df1c9e2f42f6aafe3e0a"> https://github.com/appcelerator/titanium_mobile/commit/8e7685715cea...

  2. Bill Dawson 2011-04-15

    (from [b4a40009d732f8a233f7fce967c7874c3f817790]) Expose the Android media scanner's file scanning service via Ti.Media.Android.scanMediaFiles. [#3164] https://github.com/appcelerator/titanium_mobile/commit/b4a40009d732f8a233f7fce967c7874c3f817790"> https://github.com/appcelerator/titanium_mobile/commit/b4a40009d732...

  3. Bill Dawson 2011-04-15

    QE testing:

    Here is a good test app.js:

       Titanium.UI.setBackgroundColor('#000');
       var win = Titanium.UI.createWindow({  
           title:'Test',
           backgroundColor:'#000',
           exitOnClose: true
       });
       
       var lbl = Ti.UI.createLabel({
           backgroundColor: 'blue',
           color: 'yellow',
           bottom: '10dp',
           height: '80dp',
           left: '5dp',
           right: '5dp'
       });
       win.add(lbl);
       
       var btn = Ti.UI.createButton({
           title: 'Do scan'
       });
       btn.addEventListener('click', function(){
           var f = Ti.Filesystem.getFile('fj.jpg');
           f.copy("appdata://fj.jpg");
           f = Ti.Filesystem.getFile("appdata://fj.jpg");
           Ti.API.info(f.nativePath);
           Ti.Media.Android.scanMediaFiles([ f.nativePath ], null, function(e) {
               if (e.uri) {
                   lbl.text = e.uri;
               } else {
                   lbl.text = "No uri";
               }
           });
       });
       win.add(btn);
       win.open();
       

    Put the attach fj.jpg in your Resources folder. Run the app, click the button and confirm that you get a URI in the little console label at the bottom. "No Uri" means it didn't work. After you see that the uri is there, you can go to the Android Gallery application and see the photo (a picture of the casket of Emperor Franz Josef of Austria).

  4. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/22/11 09:36 42d2187) on
    Emulator 2.1
    Samsung Nexus S 2.3.2

JSON Source