Этот коммит содержится в:
Anton Tananaev
2017-04-08 17:47:54 +12:00
родитель 9bae6e554f
Коммит d632c7cdfa
+21 -14
Просмотреть файл
@@ -37,26 +37,33 @@ public class TrackingService extends Service {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static Notification createNotification(Context context) { private static Notification createNotification(Context context) {
Intent notificationIntent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
try {
Method method = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class); return new Notification.Builder(context)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.settings_status_on_summary))
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_MIN)
.build();
} else {
Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0);
try { try {
method.invoke(notification, context, context.getString(R.string.app_name), context.getString(R.string.settings_status_on_summary), pendingIntent); Method method = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { try {
method.invoke(notification, context, context.getString(R.string.app_name), context.getString(R.string.settings_status_on_summary), pendingIntent);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
Log.w(TAG, e);
}
} catch (SecurityException | NoSuchMethodException e) {
Log.w(TAG, e); Log.w(TAG, e);
} }
} catch (SecurityException | NoSuchMethodException e) { return notification;
Log.w(TAG, e);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
notification.priority = Notification.PRIORITY_MIN;
} }
return notification;
} }
@TargetApi(Build.VERSION_CODES.ECLAIR) @TargetApi(Build.VERSION_CODES.ECLAIR)