Skip to content

Commit 7a4d491

Browse files
committed
Use Support Library's NotificationCompat.Builder
1 parent 2047601 commit 7a4d491

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/com/noshufou/android/su/InstallReceiver.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.content.pm.PackageInfo;
2525
import android.content.pm.PackageManager;
2626
import android.content.pm.PackageManager.NameNotFoundException;
27+
import android.support.v4.app.NotificationCompat;
2728
import android.util.Log;
2829

2930
import com.noshufou.android.su.util.Util;
@@ -48,17 +49,19 @@ public void onReceive(Context context, Intent intent) {
4849
if (Util.isPackageMalicious(context, packageInfo) != 0) {
4950
NotificationManager nm =
5051
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
51-
Notification notification = new Notification(R.drawable.stat_su,
52-
context.getString(R.string.malicious_app_notification_ticker),
53-
System.currentTimeMillis());
54-
CharSequence contentTitle = context.getString(R.string.app_name);
55-
CharSequence contentText = context.getString(R.string.malicious_app_notification_text,
56-
pm.getApplicationLabel(packageInfo.applicationInfo));
5752
Intent notificationIntent = new Intent(Intent.ACTION_DELETE, intent.getData());
5853
PendingIntent contentIntent =
5954
PendingIntent.getActivity(context, 0, notificationIntent, 0);
60-
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
61-
notification.flags |= Notification.FLAG_AUTO_CANCEL;
55+
Notification notification = new NotificationCompat.Builder(context)
56+
.setSmallIcon(R.drawable.stat_su)
57+
.setTicker(context.getText(R.string.malicious_app_notification_ticker))
58+
.setWhen(System.currentTimeMillis())
59+
.setContentTitle(context.getText(R.string.app_name))
60+
.setContentText(context.getString(R.string.malicious_app_notification_text,
61+
pm.getApplicationLabel(packageInfo.applicationInfo)))
62+
.setContentIntent(contentIntent)
63+
.setAutoCancel(true)
64+
.getNotification();
6265
nm.notify(0, notification);
6366
}
6467
}

src/com/noshufou/android/su/service/ResultService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import android.net.Uri;
1414
import android.os.Handler;
1515
import android.preference.PreferenceManager;
16-
import android.util.Log;
16+
import android.support.v4.app.NotificationCompat;
1717
import android.widget.Toast;
1818

1919
import com.noshufou.android.su.HomeActivity;
@@ -150,11 +150,16 @@ public void run() {
150150
// TODO: Include extras to tell HomeActivity what to do
151151
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
152152
notificationIntent, 0);
153-
Notification notification = new Notification(R.drawable.stat_su,
154-
notificationMessage, currentTime);
155-
notification.setLatestEventInfo(this, getString(R.string.app_name),
156-
notificationMessage, contentIntent);
157-
notification.flags |= Notification.FLAG_AUTO_CANCEL|Notification.FLAG_ONLY_ALERT_ONCE;
153+
Notification notification = new NotificationCompat.Builder(this)
154+
.setSmallIcon(R.drawable.stat_su)
155+
.setTicker(notificationMessage)
156+
.setWhen(System.currentTimeMillis())
157+
.setContentTitle(getText(R.string.app_name))
158+
.setContentText(notificationMessage)
159+
.setContentIntent(contentIntent)
160+
.setAutoCancel(true)
161+
.setOnlyAlertOnce(true)
162+
.getNotification();
158163
nm.notify(callerUid, notification);
159164
}
160165
}

src/com/noshufou/android/su/util/Util.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import android.graphics.drawable.Drawable;
4747
import android.os.Build;
4848
import android.preference.PreferenceManager;
49+
import android.support.v4.app.NotificationCompat;
4950
import android.text.format.DateFormat;
5051
import android.util.Log;
5152
import android.util.SparseArray;
@@ -617,13 +618,18 @@ public static void showOutdatedNotification(Context context) {
617618
.getBoolean(Preferences.OUTDATED_NOTIFICATION, true)) {
618619
NotificationManager nm =
619620
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
620-
Notification notification = new Notification(R.drawable.stat_su,
621-
context.getString(R.string.notif_outdated_ticker), System.currentTimeMillis());
622621
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
623622
new Intent(context, UpdaterActivity.class), 0);
624-
notification.setLatestEventInfo(context, context.getString(R.string.notif_outdated_title),
625-
context.getString(R.string.notif_outdated_text), contentIntent);
626-
notification.flags |= Notification.FLAG_AUTO_CANCEL;
623+
Notification notification = new NotificationCompat.Builder(context)
624+
.setSmallIcon(R.drawable.stat_su)
625+
.setTicker(context.getText(R.string.notif_outdated_ticker))
626+
.setWhen(System.currentTimeMillis())
627+
.setContentTitle(context.getText(R.string.notif_outdated_title))
628+
.setContentText(context.getText(R.string.notif_outdated_text))
629+
.setContentIntent(contentIntent)
630+
.setAutoCancel(true)
631+
.setOnlyAlertOnce(true)
632+
.getNotification();
627633
nm.notify(UpdaterService.NOTIFICATION_ID, notification);
628634
}
629635
}

0 commit comments

Comments
 (0)