Use v4.app.NotificationCompat
This commit is contained in:
parent
b2d6e79d30
commit
0f16b71688
@ -29,18 +29,20 @@ import java.util.List;
|
|||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
|
||||||
public class UpdateService extends IntentService implements ProgressListener {
|
public class UpdateService extends IntentService implements ProgressListener {
|
||||||
|
|
||||||
@ -254,29 +256,34 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
Log.d("FDroid", "Notifying updates. Apps before:" + prevUpdates
|
Log.d("FDroid", "Notifying updates. Apps before:" + prevUpdates
|
||||||
+ ", apps after: " + newUpdates);
|
+ ", apps after: " + newUpdates);
|
||||||
if (newUpdates > prevUpdates) {
|
if (newUpdates > prevUpdates) {
|
||||||
NotificationManager n = (NotificationManager) getSystemService(
|
NotificationCompat.Builder mBuilder =
|
||||||
Context.NOTIFICATION_SERVICE);
|
new NotificationCompat.Builder(this)
|
||||||
Notification notification = new Notification(R.drawable.icon,
|
.setSmallIcon(R.drawable.icon)
|
||||||
getString(R.string.fdroid_updates_available),
|
.setLargeIcon(
|
||||||
System.currentTimeMillis());
|
BitmapFactory.decodeResource(getResources(), R.drawable.icon))
|
||||||
Context context = getApplicationContext();
|
.setAutoCancel(true)
|
||||||
Intent notificationIntent = new Intent(UpdateService.this,
|
.setContentTitle(getString(R.string.fdroid_updates_available));
|
||||||
FDroid.class);
|
Intent notifyIntent = new Intent(this, FDroid.class)
|
||||||
notificationIntent.putExtra(FDroid.EXTRA_TAB_UPDATE, true);
|
.putExtra(FDroid.EXTRA_TAB_UPDATE, true);
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
if (newUpdates > 1) {
|
||||||
UpdateService.this, 0, notificationIntent, 0);
|
mBuilder.setContentText(getString(
|
||||||
CharSequence notification_text;
|
R.string.many_updates_available, newUpdates));
|
||||||
if (newUpdates > 1)
|
|
||||||
notification_text = getString(
|
} else {
|
||||||
R.string.many_updates_available, newUpdates);
|
mBuilder.setContentText(getString(
|
||||||
else
|
R.string.one_update_available));
|
||||||
notification_text = getString(
|
}
|
||||||
R.string.one_update_available);
|
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this)
|
||||||
notification.setLatestEventInfo(context,
|
.addParentStack(FDroid.class)
|
||||||
getString(R.string.app_name),
|
.addNextIntent(notifyIntent);
|
||||||
notification_text, contentIntent);
|
PendingIntent pendingIntent =
|
||||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
stackBuilder.getPendingIntent(0,
|
||||||
n.notify(1, notification);
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
);
|
||||||
|
mBuilder.setContentIntent(pendingIntent);
|
||||||
|
NotificationManager mNotificationManager =
|
||||||
|
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
mNotificationManager.notify(1, mBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user