Skip to content

Instantly share code, notes, and snippets.

@AlexSuvorov2k
Created September 17, 2018 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexSuvorov2k/c55c05e4ba9ebd5aef3351928db04dc6 to your computer and use it in GitHub Desktop.
Save AlexSuvorov2k/c55c05e4ba9ebd5aef3351928db04dc6 to your computer and use it in GitHub Desktop.
Android 8 notification example
private void sendNotificationSos(String title, String msg, boolean sound, JSONObject params) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
/*Intent intent = new Intent(this, HelpMapActivity.class);
try {
intent.putExtra("lat", params.getString("lat"));
intent.putExtra("lon", params.getString("lon"));
intent.putExtra("car_data", params.getString("car_data"));
} catch (JSONException e) {
e.printStackTrace();
}
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
*/
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.push)
.setContentTitle(title)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000})
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
//mBuilder.setContentIntent(contentIntent);
if (sound) {
if (Sound.getSound("ringtone_sos").isDefault()) {
mBuilder.setSound(Uri.parse("android.resource://" + getPackageName() + "/"
+ Tools.getResourceId(getApplicationContext(), "sos", Locale.getDefault().getLanguage())));
} else {
mBuilder.setSound(Uri.parse(Sound.getSound("ringtone_sos").getPath()));
}
}
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment