-
Notifications
You must be signed in to change notification settings - Fork 20
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
Update LocalNotifications.java #19
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.Random; | ||
import android.app.NotificationChannel; | ||
|
||
/** | ||
* This class exposes methods in Cordova that can be called from JavaScript. | ||
|
@@ -69,14 +70,14 @@ public boolean execute(String action, final JSONArray args, final CallbackContex | |
} | ||
|
||
private void showNotification(JSONArray args) throws JSONException { | ||
// Get args | ||
// Get args | ||
String title = args.getString(0); | ||
String dir = args.getString(1); | ||
String lang = args.getString(2); | ||
String body = args.getString(3); | ||
String tag = args.getString(4); | ||
String icon = args.getString(5); | ||
|
||
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; | ||
Context context = cordova.getActivity(); | ||
|
||
Intent notificationIntent = new Intent(context, NotificationHandlerActivity.class); | ||
|
@@ -86,10 +87,20 @@ private void showNotification(JSONArray args) throws JSONException { | |
int requestCode = new Random().nextInt(); | ||
PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
|
||
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
NotificationCompat.Builder mBuilder = null; | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | ||
int importance = NotificationManager.IMPORTANCE_DEFAULT; | ||
NotificationChannel notificationChannel = new NotificationChannel("ID", "Name", importance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The channel should be named differently. Maybe id="default" and name="Default"? Also, just use |
||
mNotificationManager.createNotificationChannel(notificationChannel); | ||
mBuilder = new NotificationCompat.Builder(context, notificationChannel.getId()); | ||
} else { | ||
mBuilder = new NotificationCompat.Builder(context); | ||
} | ||
|
||
// Build notifications | ||
NotificationCompat.Builder mBuilder = | ||
new NotificationCompat.Builder(context) | ||
mBuilder = mBuilder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the |
||
.setWhen(System.currentTimeMillis()) | ||
.setContentTitle(title) | ||
.setContentText(body) | ||
|
@@ -103,7 +114,7 @@ private void showNotification(JSONArray args) throws JSONException { | |
} | ||
|
||
// Show notification | ||
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
mNotificationManager.notify(tag, 0, mBuilder.build()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string is not used