mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-13 13:05:03 -05:00
49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
|
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;
|
||
|
|
||
|
|
||
|
public class MediaScannerNotifier implements MediaScannerConnectionClient
|
||
|
{
|
||
|
private MediaScannerConnection mConnection;
|
||
|
private File mFile;
|
||
|
private Context mContext;
|
||
|
|
||
|
public MediaScannerNotifier(Context context, File file)
|
||
|
{
|
||
|
mFile = file;
|
||
|
mConnection = new MediaScannerConnection(context, this);
|
||
|
mConnection.connect();
|
||
|
mContext = context;
|
||
|
|
||
|
}
|
||
|
|
||
|
public void onMediaScannerConnected()
|
||
|
{
|
||
|
mConnection.scanFile(mFile.getAbsolutePath(), null);
|
||
|
}
|
||
|
|
||
|
public void onScanCompleted(String path, Uri uri)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (uri != null)
|
||
|
{
|
||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||
|
intent.setData(uri);
|
||
|
mContext.startActivity(intent);
|
||
|
}
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
mConnection.disconnect();
|
||
|
}
|
||
|
}
|
||
|
}
|