diff --git a/plugin.xml b/plugin.xml index 835c4940d..ec35b7e37 100755 --- a/plugin.xml +++ b/plugin.xml @@ -30,9 +30,11 @@ + + @@ -69,6 +71,7 @@ + diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index ee15bcdc9..a81e5e2d9 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -1,6 +1,7 @@ package com.adobe.phonegap.push; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -361,9 +362,6 @@ private void showNotificationIfPossible (Context context, Bundle extras) { Log.d(LOG_TAG, "forceStart =[" + forceStart + "]"); if ((message != null && message.length() != 0) || (title != null && title.length() != 0)) { - - Log.d(LOG_TAG, "create notification"); - if (title == null || title.isEmpty()) { extras.putString(TITLE, getAppName(this)); } @@ -387,13 +385,16 @@ private void showNotificationIfPossible (Context context, Bundle extras) { } public void createNotification (Context context, Bundle extras) { + Log.d(LOG_TAG, "create notification"); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String appName = getAppName(this); String packageName = context.getPackageName(); Resources resources = context.getResources(); - + boolean fullScreenIntent = extras.getString(FULL_SCREEN_NOTIFICATION, "").equals("1"); + Log.d(LOG_TAG, "fullScreenIntent = " + fullScreenIntent); int notId = parseInt(NOT_ID, extras); - Intent notificationIntent = new Intent(this, PushHandlerActivity.class); + Class activityClass = fullScreenIntent ? FullScreenActivity.class : PushHandlerActivity.class; + Intent notificationIntent = new Intent(this, activityClass); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra(PUSH_BUNDLE, extras); notificationIntent.putExtra(NOT_ID, notId); @@ -434,10 +435,9 @@ public void createNotification (Context context, Bundle extras) { } else { channelID = DEFAULT_CHANNEL_ID; } - Log.d(LOG_TAG, "Using channel ID = " + channelID); mBuilder = new NotificationCompat.Builder(context, channelID); } - + Log.d(LOG_TAG, "Using channel ID = " + channelID); } else { mBuilder = new NotificationCompat.Builder(context); } @@ -449,6 +449,14 @@ public void createNotification (Context context, Bundle extras) { .setDeleteIntent(deleteIntent) .setAutoCancel(true); + if (fullScreenIntent) { + mBuilder + .setFullScreenIntent(contentIntent, true) + .setPriority(NotificationCompat.PRIORITY_HIGH); + } else { + mBuilder.setContentIntent(contentIntent); + } + SharedPreferences prefs = context.getSharedPreferences( PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE diff --git a/src/android/com/adobe/phonegap/push/FullScreenActivity.java b/src/android/com/adobe/phonegap/push/FullScreenActivity.java new file mode 100644 index 000000000..5891e02be --- /dev/null +++ b/src/android/com/adobe/phonegap/push/FullScreenActivity.java @@ -0,0 +1,85 @@ +package com.adobe.phonegap.push; + +import android.app.Activity; +import android.app.KeyguardManager; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.WindowManager; + +public class FullScreenActivity extends Activity implements PushConstants { + private static final String LOG_TAG = "FullScreenActivity"; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + Log.d(LOG_TAG, "onCreate"); + super.onCreate(savedInstanceState); + + turnScreenOnAndKeyguardOff(); + forceMainActivityReload(); + finish(); + } + + private void forceMainActivityReload () { + PackageManager pm = getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName()); + + launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + launchIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); + + startActivity(launchIntent); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + turnScreenOffAndKeyguardOn(); + } + + private void turnScreenOnAndKeyguardOff() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + Log.d(LOG_TAG, "setShowWhenLocked"); + setShowWhenLocked(true); + setTurnScreenOn(true); + } else { + Log.d(LOG_TAG, "addFlags"); + getWindow().addFlags( + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON + ); + } + Object candidate = getSystemService(Context.KEYGUARD_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && candidate != null) { + KeyguardManager keyguardManager = (KeyguardManager) candidate; + keyguardManager.requestDismissKeyguard(this, new KeyguardManager.KeyguardDismissCallback() { + @Override + public void onDismissError() { + super.onDismissError(); + Log.d(LOG_TAG, "onDismissError"); + } + + @Override + public void onDismissSucceeded() { + super.onDismissSucceeded(); + Log.d(LOG_TAG, "onDismissSucceeded"); + } + }); + } + } + + private void turnScreenOffAndKeyguardOn() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(false); + setTurnScreenOn(false); + } else { + getWindow().clearFlags( + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON + ); + } + } +} diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 0235b2d73..5b1fb778d 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -103,4 +103,5 @@ public interface PushConstants { public static final String LIST_CHANNELS = "listChannels"; public static final String CLEAR_NOTIFICATION = "clearNotification"; public static final String MESSAGE_ID = "google.message_id"; + public static final String FULL_SCREEN_NOTIFICATION = "full-screen-notification"; }