Commit 0d0b0eae authored by Libin Lu's avatar Libin Lu

add wake_screen

parent 3877ad8a
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk <uses-sdk
android:minSdkVersion="16" android:minSdkVersion="16"
......
...@@ -83,7 +83,8 @@ export default class App extends Component { ...@@ -83,7 +83,8 @@ export default class App extends Component {
priority: "high", priority: "high",
large_icon: "https://image.freepik.com/free-icon/small-boy-cartoon_318-38077.jpg", large_icon: "https://image.freepik.com/free-icon/small-boy-cartoon_318-38077.jpg",
show_in_foreground: true, show_in_foreground: true,
picture: 'https://firebase.google.com/_static/af7ae4b3fc/images/firebase/lockup.png' picture: 'https://firebase.google.com/_static/af7ae4b3fc/images/firebase/lockup.png',
wake_screen: true
}); });
} }
......
...@@ -15,6 +15,7 @@ import android.net.Uri; ...@@ -15,6 +15,7 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
...@@ -35,7 +36,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> { ...@@ -35,7 +36,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private Boolean mIsForeground; private Boolean mIsForeground;
public SendNotificationTask(Context context, SharedPreferences sharedPreferences, Boolean mIsForeground, Bundle bundle){ SendNotificationTask(Context context, SharedPreferences sharedPreferences, Boolean mIsForeground, Bundle bundle){
this.mContext = context; this.mContext = context;
this.bundle = bundle; this.bundle = bundle;
this.sharedPreferences = sharedPreferences; this.sharedPreferences = sharedPreferences;
...@@ -215,6 +216,16 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> { ...@@ -215,6 +216,16 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
NotificationManagerCompat.from(mContext).notify(notificationID, info); NotificationManagerCompat.from(mContext).notify(notificationID, info);
} }
if(bundle.getBoolean("wake_screen", false)){
PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
if(pm != null && !pm.isScreenOn())
{
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"FCMLock");
wl.acquire(5000);
}
}
//clear out one time scheduled notification once fired //clear out one time scheduled notification once fired
if(!bundle.containsKey("repeat_interval") && bundle.containsKey("fire_date")) { if(!bundle.containsKey("repeat_interval") && bundle.containsKey("fire_date")) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
...@@ -227,7 +238,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> { ...@@ -227,7 +238,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
return null; return null;
} }
public Bitmap getBitmapFromURL(String strURL) { private Bitmap getBitmapFromURL(String strURL) {
try { try {
URL url = new URL(strURL); URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
...@@ -241,11 +252,10 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> { ...@@ -241,11 +252,10 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
} }
} }
public String getMainActivityClassName() { protected String getMainActivityClassName() {
String packageName = mContext.getPackageName(); String packageName = mContext.getPackageName();
Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage(packageName); Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName(); return launchIntent != null ? launchIntent.getComponent().getClassName() : null;
return className;
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment