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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---