Currently I am using IntentService to loop urls in the Browser.apk. I am running it until the battery drains. Here is my dirty code. =)
@Override
protected void onHandleIntent(Intent intent) {
int size = intent.getStringArrayExtra("addresses").length;
int counter = sp.getInt("counter", 0);
String address = intent.getStringArrayExtra("addresses")[counter];
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(address));
i.setFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
counter++;
if(counter == size) {
counter = 0;
}
spe.putInt("counter", counter);
spe.commit();
}
I tried to use wakelock but not all devices stays awake. It is working with Motorola Xoom but not in Thinkpad tablet slate.
Do you know other option other than using the wakelock. Or How should I properly implement the wakelock?
Can I tell the Browser that I should keep the Screen On while loading the urls? By using intent or other means.
For open the device screen, if the device is in sleep mode, use the code below:
//acquireLock(context);
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Log.e("screen on.................................", ""+isScreenOn);
if(isScreenOn==false)
{
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock");
wl.acquire(10000);
WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock");
wl_cpu.acquire(10000);
}