Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full screen activity #137

Open
wants to merge 5 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.FullScreenActivity" android:showOnLockScreen="true" android:turnScreenOn="true" android:theme="@android:style/Theme.DeviceDefault.NoActionBar"/>
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
<activity android:name="com.adobe.phonegap.push.BackgroundHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.BackgroundHandlerActivity">
<intent-filter>
Expand Down Expand Up @@ -69,6 +71,7 @@
<framework src="me.leolin:ShortcutBadger:1.1.17@aar"/>
<framework src="com.google.firebase:firebase-messaging:$FCM_VERSION"/>

<source-file src="src/android/com/adobe/phonegap/push/FullScreenActivity.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/FCMService.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.java" target-dir="src/com/adobe/phonegap/push/"/>
Expand Down
22 changes: 15 additions & 7 deletions src/android/com/adobe/phonegap/push/FCMService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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<? extends Activity> 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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
85 changes: 85 additions & 0 deletions src/android/com/adobe/phonegap/push/FullScreenActivity.java
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}