let media scanner scan backup file. fixes #3913
note that the ROMs I tested this on don’t require scanning for it to appear on MTP. However it certainly don’t hurt either.
This commit is contained in:
parent
0c563134da
commit
c7ec6a9dae
|
@ -58,7 +58,7 @@ public class ExportBackupService extends Service {
|
||||||
|
|
||||||
private static final int NOTIFICATION_ID = 19;
|
private static final int NOTIFICATION_ID = 19;
|
||||||
private static final int PAGE_SIZE = 20;
|
private static final int PAGE_SIZE = 20;
|
||||||
private static AtomicBoolean running = new AtomicBoolean(false);
|
private static final AtomicBoolean RUNNING = new AtomicBoolean(false);
|
||||||
private DatabaseBackend mDatabaseBackend;
|
private DatabaseBackend mDatabaseBackend;
|
||||||
private List<Account> mAccounts;
|
private List<Account> mAccounts;
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
|
@ -67,7 +67,7 @@ public class ExportBackupService extends Service {
|
||||||
|
|
||||||
//http://www.openintents.org/action/android-intent-action-view/file-directory
|
//http://www.openintents.org/action/android-intent-action-view/file-directory
|
||||||
//do not use 'vnd.android.document/directory' since this will trigger system file manager
|
//do not use 'vnd.android.document/directory' since this will trigger system file manager
|
||||||
Intent openIntent = new Intent(Intent.ACTION_VIEW);
|
final Intent openIntent = new Intent(Intent.ACTION_VIEW);
|
||||||
openIntent.addCategory(Intent.CATEGORY_DEFAULT);
|
openIntent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
if (Compatibility.runsAndTargetsTwentyFour(context)) {
|
if (Compatibility.runsAndTargetsTwentyFour(context)) {
|
||||||
openIntent.setType("resource/folder");
|
openIntent.setType("resource/folder");
|
||||||
|
@ -76,17 +76,15 @@ public class ExportBackupService extends Service {
|
||||||
}
|
}
|
||||||
openIntent.putExtra("org.openintents.extra.ABSOLUTE_PATH", path);
|
openIntent.putExtra("org.openintents.extra.ABSOLUTE_PATH", path);
|
||||||
|
|
||||||
Intent amazeIntent = new Intent(Intent.ACTION_VIEW);
|
final Intent amazeIntent = new Intent(Intent.ACTION_VIEW);
|
||||||
amazeIntent.setDataAndType(Uri.parse("com.amaze.filemanager:" + path), "resource/folder");
|
amazeIntent.setDataAndType(Uri.parse("com.amaze.filemanager:" + path), "resource/folder");
|
||||||
|
|
||||||
//will open a file manager at root and user can navigate themselves
|
//will open a file manager at root and user can navigate themselves
|
||||||
Intent systemFallBack = new Intent(Intent.ACTION_VIEW);
|
final Intent systemFallBack = new Intent(Intent.ACTION_VIEW);
|
||||||
systemFallBack.addCategory(Intent.CATEGORY_DEFAULT);
|
systemFallBack.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
systemFallBack.setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));
|
systemFallBack.setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));
|
||||||
|
|
||||||
return Arrays.asList(openIntent, amazeIntent, systemFallBack);
|
return Arrays.asList(openIntent, amazeIntent, systemFallBack);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void accountExport(final SQLiteDatabase db, final String uuid, final PrintWriter writer) {
|
private static void accountExport(final SQLiteDatabase db, final String uuid, final PrintWriter writer) {
|
||||||
|
@ -218,7 +216,7 @@ public class ExportBackupService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (running.compareAndSet(false, true)) {
|
if (RUNNING.compareAndSet(false, true)) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
boolean success;
|
boolean success;
|
||||||
List<File> files;
|
List<File> files;
|
||||||
|
@ -231,7 +229,7 @@ public class ExportBackupService extends Service {
|
||||||
files = Collections.emptyList();
|
files = Collections.emptyList();
|
||||||
}
|
}
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
running.set(false);
|
RUNNING.set(false);
|
||||||
if (success) {
|
if (success) {
|
||||||
notifySuccess(files);
|
notifySuccess(files);
|
||||||
}
|
}
|
||||||
|
@ -322,12 +320,19 @@ public class ExportBackupService extends Service {
|
||||||
}
|
}
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
|
mediaScannerScanFile(file);
|
||||||
Log.d(Config.LOGTAG, "written backup to " + file.getAbsoluteFile());
|
Log.d(Config.LOGTAG, "written backup to " + file.getAbsoluteFile());
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mediaScannerScanFile(final File file) {
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||||
|
intent.setData(Uri.fromFile(file));
|
||||||
|
sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
private void notifySuccess(final List<File> files) {
|
private void notifySuccess(final List<File> files) {
|
||||||
final String path = FileBackend.getBackupDirectory(this);
|
final String path = FileBackend.getBackupDirectory(this);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue