Skip to content

Commit

Permalink
Merge pull request #28 from shankari/make_plugins_independent
Browse files Browse the repository at this point in the history
Changes to support the location services toggle
  • Loading branch information
shankari authored Mar 4, 2019
2 parents e400a33 + 02adab2 commit beee75a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="edu.berkeley.eecs.emission.cordova.unifiedlogger"
version="1.1.0">
version="1.2.0">

<name>UnifiedLogger</name>
<description>Log messages from both native code and javacript. Since this is
Expand Down
23 changes: 20 additions & 3 deletions src/android/NotificationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;

import org.apache.cordova.CordovaActivity;
Expand All @@ -16,6 +17,7 @@

public class NotificationHelper {
private static String TAG = "NotificationHelper";
public static final String RESOLUTION_PENDING_INTENT_KEY = "rpIntentKey";

public static void createNotification(Context context, int id, String message) {
Notification.Builder builder = getNotificationBuilderForApp(context, message);
Expand Down Expand Up @@ -57,16 +59,31 @@ public static void createNotification(Context context, int id, String message, P
*
* TODO: Decide what level API we want to support, and whether we want a more comprehensive activity.
*/
builder.setContentIntent(intent);
builder.setAutoCancel(true);
Intent activityIntent = new Intent(context, MainActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityIntent.putExtra(NotificationHelper.RESOLUTION_PENDING_INTENT_KEY, intent);

PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0,
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(activityPendingIntent);
// builder.setAutoCancel(true);

NotificationManager nMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

Log.d(context, TAG, "Generating notify with id " + id + " and message " + message);
Log.d(context, TAG, "Generating notify with id " + id + ", message " + message
+ " and pending intent " + intent);
nMgr.notify(id, builder.build());
}

public static void cancelNotification(Context context, int id) {
NotificationManager nMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

Log.d(context, TAG, "Cancelling notify with id " + id);
nMgr.cancel(id);
}

public static Notification.Builder getNotificationBuilderForApp(Context context, String message) {
Notification.Builder builder = new Notification.Builder(context);
Bitmap appIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
Expand Down

0 comments on commit beee75a

Please sign in to comment.