Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a22f2124 authored by zhuw's avatar zhuw Committed by Gerrit - the friendly Code Review server
Browse files

SDGallery:Fix focus close when receive package changed intent

use startForegroundService instead of startService on O-version

Change-Id: I936b47cee1f3fbccc33cc4ee60960f27242cbfe7
parent 453df37a
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -17,10 +17,14 @@
package com.android.gallery3d.app;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import com.android.gallery3d.picasasource.PicasaSource;
@@ -37,14 +41,33 @@ public class PackagesMonitor extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {
        intent.setClass(context, AsyncService.class);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(intent);
        } else {
            context.startService(intent);
        }
    }

    public static class AsyncService extends IntentService {
        public AsyncService() {
            super("GalleryPackagesMonitorAsync");
        }

        @Override
        public void onCreate() {
            super.onCreate();
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                String channelId = "GalleryPackagesMonitorAsync";
                NotificationChannel channel = new NotificationChannel(channelId, channelId,
                        NotificationManager.IMPORTANCE_LOW);
                NotificationManager manager =
                        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.createNotificationChannel(channel);
                startForeground(KEY_PACKAGES_VERSION.hashCode(),
                        new Notification.Builder(getApplicationContext(), channelId).build());
            }
        }

        @Override
        protected void onHandleIntent(Intent intent) {
            onReceiveAsync(this, intent);