From df01e9b8b7977a099f24c65ec8d8a02ede36339b Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Tue, 9 Aug 2016 23:31:57 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20m=C3=A9thode=20pour=20avoir=20le=20nom?= =?UTF-8?q?=20de=20l'application=20(sans=20doute=20=C3=A0=20d=C3=A9placer?= =?UTF-8?q?=20dans=20une=20class=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changement du titre de la notification (avec le nom de l'application) --- .../net/foucry/pilldroid/MedicamentListActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 07044ee..139f61e 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -7,6 +7,8 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; @@ -335,12 +337,20 @@ public class MedicamentListActivity extends AppCompatActivity { private Notification getNotification(String content) { Notification.Builder builder = new Notification.Builder(this); - builder.setContentTitle("Scheduled Notification"); + builder.setContentTitle(getAppName()); builder.setContentText(content); builder.setSmallIcon(R.mipmap.ic_launcher); return builder.build(); } + private String getAppName() { + PackageManager packageManager = getApplicationContext().getPackageManager(); + ApplicationInfo applicationInfo = null; + try { + applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0); + } catch (final PackageManager.NameNotFoundException e) {} + return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); + } /** * SimpleItemRecyclerViewAdapter */