How to wake an Android phone from sleep?

How to connect an Android phone from sleep (suspend to memory) programmatically? I do not want to purchase any wakelock, which means that the phone goes into a "real" dream with the processor turned off. I think I can use some kind of RTC mechanism (real time clock)?

Does anyone have any examples?

Thanks.

+7
android sleep wakeup real-time-clock
source share
3 answers

In order for Activity to activate the device and not require a password / scroll, you only need to add a few flags. To get this, include in your code:

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 

This will awaken the activity of your application.

+7
source share

I just wrote an application that can do this, here is an example code: First, I create an AlarmManager and set an alarm for a certain time:

 AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 15); calendar.set(Calendar.MINUTE, 30); calendar.set(Calendar.SECOND, 0); // if the time is before now then add one day to it if(calendar.getTimeInMillis() < System.currentTimeMillis()) calendar.setTimeInMillis(calendar.getTimeInMillis()+86400000); manager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 0); 

I need a BroadcastReciever to receive this signal. To do this, I have to make my manifest:

 <application ...> <receiver android:name="hu.bendaf.example.AlarmReceiver"/> ... </application> 

and I also have an AlarmReciever class that fires my main activity:

 public class AlarmReceiver extends BroadcastReceiver { public static final String WAKE = "Wake up"; @Override public void onReceive(Context context, Intent intent) { //Starting MainActivity Intent myAct = new Intent(context, MainActivity.class); myAct.putExtra(WAKE, true); myAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(myAct); } } 

and in my ActivityCreate function I have:

 // Wake up phone if needed if(getIntent().hasExtra(AlarmReceiver.WAKE) && getIntent().getExtras().getBoolean(AlarmReceiver.WAKE)){ this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); } 

This code wakes up my phone at 15:30:00 (either today or tomorrow).

+1
source share

Use the AlarmManager to broadcast intentions while you want to make work and wake up. In BroadcastReceiver, either do the work you need to do (if it is short), or get WakeLock (possibly through one singleton), start the service, start the service, then you have the WakeLock release service.

You can read about it here: https://groups.google.com/forum/#!topic/android-developers/5--QRAPlFL0

0
source share

All Articles