Last active
June 2, 2016 12:42
-
-
Save supercairos/eca6268dae54dee8bc928f63e80988a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
...> | |
... | |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | |
... | |
<application | |
...> | |
... | |
<receiver | |
android:name=".receivers.BootCompletedReceiver" | |
android:enabled="true" | |
android:exported="true"> | |
<intent-filter> | |
<action android:name="android.intent.action.BOOT_COMPLETED" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BootCompletedReceiver extends BroadcastReceiver { | |
public BootCompletedReceiver() { | |
} | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// launching demo app | |
context.startActivity(new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK )); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private PowerManager.WakeLock mWakeLock; | |
.... | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState) | |
// Some code ... | |
// Some more code ... | |
// More code ... | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); | |
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); | |
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); | |
mWakeLock.setReferenceCounted(false); | |
mWakeLock.acquire(); | |
} | |
... | |
@Override | |
protected void onDestroy() { | |
mWakeLock.release(); | |
super.onDestroy(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment