Please help with Android development

by Nerses Zackoyan » Wed, 14 May 2008 11:55:58 GMT


Sponsored Links
 Dear Android Staff,

I have problem with getting event onChange(boolean selfchange) in
ContentObserver when I set getContentResolver().registerContentObserver(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI ,
true,imageObserver );  and add image file in sdcard using ddms or using
FileOutputStream() .
Also the "media" database in sdcard doesn't refresh data if I add image file
in sdcard. It refreshes only if I restart emulator or if I add using
android.provider.MediaStore.Images.Media.insertImage().

Here is my code:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import android.app.Service;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;

public class PhService extends Service {

        Logger logger=new Logger();
    private Handler handler = new Handler();

    private ImagesObserver imageObserver = null;

    class ImagesObserver extends ContentObserver {
      public ImagesObserver( Handler h ) {
        super( h );
      }

      public void onChange(boolean selfChange) {
          show();
      }
    }

    public void show(){
        logger.record("content images", "changed");
    }

    @Override
    public void onCreate() {
        logger.record("content images", "created");
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

    @Override
    protected void onStart(int startId, Bundle arguments) {
        // TODO Auto-generated method stub
        logger.record("content images", "started");
        registerContentObservers();
    }

// Set up content observer for our content provider
    private void registerContentObservers() {
     ContentResolver cr = getContentResolver();
      imageObserver = new ImagesObserver( handler );
      cr.registerContentObserver(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI ,
true,imageObserver );


    }

    private void unregisterContentObservers() {
      ContentResolver cr = getContentResolver();

      if( imageObserver != null ) {        // just paranoia
        cr.unregisterContentObserver( imageObserver );
        imageObserver = null;
      }
    }



    @Override
    public IBinder onBind(Intent intent) {
        //Toast.makeText(this, R.string.no_items,
Toast.LENGTH_SHORT).show();
        // TODO Auto-generated method stub
        return null;
    }
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks,

Nerses.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to iterate a View<Group> for a specific view id?

findViewById()






-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~

2. Customize desktop icon

Hi,

I have created several folders (Apps, Games, etc) on my G1 desktop.

So my question are:

1) Is there a way of changing the icon of the folders from the dull
plain grey one provided ?
if so how ?

2) Where are those folders created on the system ?

Thank you

--~--~---------~--~----~------------~-------~--~----~

3. Your "installed" percentage

4. Pausing threads in onPause and resuming in onResume?

5. It is now MID-Q1, where are the Paid Apps?

6. Failed sending reply to debugger: Broken pipe error

7. "(fix?) We're on the simulator; assuming data is connected" ???