How can an Android application find out that files have been modified from a PC? -
How can an Android application find out that files have been modified from a PC? -
my application accessing files single special directory. want application notified when user connects device computer , modifies files (adds, removes, renames etc.). per-file notifications not necessary, application needs know should rescan directory. ideal solution work sd card.
the fileobserver
doesn't work in case (and documentation indirectly says so).
i have tried using broadcastreceiver
watch action_media_mounted
intent, no luck. since i'm interested in sound files, have experimented action_media_scanner_started
has proven unreliable: works on sgs3 not on nexus 7 android 5.1. assume media scanner not guaranteed run on devices.
i seek using combination of different methods (watching of intents come mind above , maybe others lie action_power_disconnected
) if possible, i'd utilize more reliable approach.
i wasn't able find solution think have found satisfactory one.
i have switched watching intent.action_media_scanner_started
using contentobserver
. contentobserver.onchange
method called multiple times utilize timer delay actual file scan on each phone call onchange
.
public class mediastoreupdateobserver extends contentobserver { private static final int rescan_delay_ms = 15000; private final handler mainthreadhandler; public mediastoreupdateobserver(handler mainthreadhandler) { super(mainthreadhandler); this.mainthreadhandler = mainthreadhandler; } @override public void onchange(boolean selfchange) { mainthreadhandler.removecallbacks(delayedrescantask); mainthreadhandler.postdelayed(delayedrescantask, rescan_delay_ms); } private final runnable delayedrescantask = new runnable() { @override public void run() { // start file rescan. } }; }
again, hack, job.
android
Comments
Post a Comment