Methods Summary |
---|
private void | closeDatabase(java.lang.String volumeName)
try {
getContentResolver().delete(
Uri.parse("content://media/" + volumeName), null, null);
} catch (Exception e) {
Log.w(TAG, "failed to close media database " + volumeName + " exception: " + e);
}
|
private android.media.MediaScanner | createMediaScanner()
MediaScanner scanner = new MediaScanner(this);
Locale locale = getResources().getConfiguration().locale;
if (locale != null) {
String language = locale.getLanguage();
String country = locale.getCountry();
String localeString = null;
if (language != null) {
if (country != null) {
scanner.setLocale(language + "_" + country);
} else {
scanner.setLocale(language);
}
}
}
return scanner;
|
public android.os.IBinder | onBind(android.content.Intent intent)
return mBinder;
|
public void | onCreate()
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
// Start up the thread running the service. Note that we create a
// separate thread because the service normally runs in the process's
// main thread, which we don't want to block.
Thread thr = new Thread(null, this, "MediaScannerService");
thr.start();
|
public void | onDestroy()
// Make sure thread has started before telling it to quit.
while (mServiceLooper == null) {
synchronized (this) {
try {
wait(100);
} catch (InterruptedException e) {
}
}
}
mServiceLooper.quit();
|
public void | onStart(android.content.Intent intent, int startId)
while (mServiceHandler == null) {
synchronized (this) {
try {
wait(100);
} catch (InterruptedException e) {
}
}
}
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent.getExtras();
mServiceHandler.sendMessage(msg);
|
private void | openDatabase(java.lang.String volumeName)
try {
ContentValues values = new ContentValues();
values.put("name", volumeName);
getContentResolver().insert(Uri.parse("content://media/"), values);
} catch (IllegalArgumentException ex) {
Log.w(TAG, "failed to open media database");
}
|
public void | run()
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
Looper.prepare();
mServiceLooper = Looper.myLooper();
mServiceHandler = new ServiceHandler();
Looper.loop();
|
private void | scan(java.lang.String[] directories, java.lang.String volumeName)
// don't sleep while scanning
mWakeLock.acquire();
ContentValues values = new ContentValues();
values.put(MediaStore.MEDIA_SCANNER_VOLUME, volumeName);
Uri scanUri = getContentResolver().insert(MediaStore.getMediaScannerUri(), values);
Uri uri = Uri.parse("file://" + directories[0]);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_STARTED, uri));
try {
if (volumeName.equals(MediaProvider.EXTERNAL_VOLUME)) {
openDatabase(volumeName);
}
MediaScanner scanner = createMediaScanner();
scanner.scanDirectories(directories, volumeName);
} catch (Exception e) {
Log.e(TAG, "exception in MediaScanner.scan()", e);
}
getContentResolver().delete(scanUri, null, null);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_FINISHED, uri));
mWakeLock.release();
|
private android.net.Uri | scanFile(java.lang.String path, java.lang.String mimeType)
String volumeName = MediaProvider.INTERNAL_VOLUME;
String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
if (path.startsWith(externalStoragePath)) {
volumeName = MediaProvider.EXTERNAL_VOLUME;
openDatabase(volumeName);
}
MediaScanner scanner = createMediaScanner();
return scanner.scanSingleFile(path, volumeName, mimeType);
|