2011-01-06 11:56:20 -05:00
|
|
|
package com.fsck.k9.helper;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class MediaScannerNotifier implements MediaScannerConnectionClient {
|
2011-01-06 11:56:20 -05:00
|
|
|
private MediaScannerConnection mConnection;
|
|
|
|
private File mFile;
|
|
|
|
private Context mContext;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public MediaScannerNotifier(Context context, File file) {
|
2011-01-06 11:56:20 -05:00
|
|
|
mFile = file;
|
|
|
|
mConnection = new MediaScannerConnection(context, this);
|
|
|
|
mConnection.connect();
|
|
|
|
mContext = context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onMediaScannerConnected() {
|
2011-01-06 11:56:20 -05:00
|
|
|
mConnection.scanFile(mFile.getAbsolutePath(), null);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onScanCompleted(String path, Uri uri) {
|
|
|
|
try {
|
|
|
|
if (uri != null) {
|
2011-01-06 11:56:20 -05:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(uri);
|
|
|
|
mContext.startActivity(intent);
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} finally {
|
2011-01-06 11:56:20 -05:00
|
|
|
mConnection.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|