Created
September 17, 2018 07:48
-
-
Save AlexSuvorov2k/c55c05e4ba9ebd5aef3351928db04dc6 to your computer and use it in GitHub Desktop.
Android 8 notification example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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