diff --git a/app/build.gradle b/app/build.gradle index 93de6bf..62f4de5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,7 +22,7 @@ android { minSdkVersion 21 targetSdkVersion 29 - versionCode 4 + versionCode 5 versionName "1.1" resConfigs "en", "fr" diff --git a/app/src/main/java/com/farmerbb/appnotifier/AppNotifierService.kt b/app/src/main/java/com/farmerbb/appnotifier/AppNotifierService.kt index c5ebac0..82fa573 100644 --- a/app/src/main/java/com/farmerbb/appnotifier/AppNotifierService.kt +++ b/app/src/main/java/com/farmerbb/appnotifier/AppNotifierService.kt @@ -21,8 +21,8 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.pm.PackageManager import android.os.Build -import android.os.IBinder import android.provider.Settings import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat @@ -41,7 +41,11 @@ class AppNotifierService: Service() { private val packageAddedReceiver = object: BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val packageName = intent.dataString?.removePrefix("package:").orEmpty() - val appInfo = packageManager.getApplicationInfo(packageName, 0) + val appInfo = try { + packageManager.getApplicationInfo(packageName, 0) + } catch (e: PackageManager.NameNotFoundException) { + return + } if(intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) controller.buildAppUpdateNotification(appInfo) @@ -97,6 +101,6 @@ class AppNotifierService: Service() { unregisterReceiver(packageRemovedReceiver) } - override fun onStartCommand(intent: Intent, flags: Int, startId: Int) = Service.START_STICKY + override fun onStartCommand(intent: Intent, flags: Int, startId: Int) = START_STICKY override fun onBind(intent: Intent) = null } \ No newline at end of file diff --git a/app/src/main/java/com/farmerbb/appnotifier/NotificationController.kt b/app/src/main/java/com/farmerbb/appnotifier/NotificationController.kt index ad1d304..84b31a2 100644 --- a/app/src/main/java/com/farmerbb/appnotifier/NotificationController.kt +++ b/app/src/main/java/com/farmerbb/appnotifier/NotificationController.kt @@ -136,6 +136,8 @@ import kotlin.math.min val iconBitmap = getApplicationIcon(appInfo) val contentIntent = context.packageManager.getLaunchIntentForPackage(appInfo.packageName) + ?: getPlayStoreLaunchIntent(appInfo.packageName) + val pendingContentIntent = PendingIntent.getActivity(context, 0, contentIntent, FLAGS) val builder = NotificationCompat.Builder(context, channelId) diff --git a/app/src/main/java/com/farmerbb/appnotifier/Utils.kt b/app/src/main/java/com/farmerbb/appnotifier/Utils.kt index dd1ddf4..911f7f8 100644 --- a/app/src/main/java/com/farmerbb/appnotifier/Utils.kt +++ b/app/src/main/java/com/farmerbb/appnotifier/Utils.kt @@ -23,6 +23,7 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.os.Build +import androidx.core.net.toUri import androidx.preference.PreferenceManager fun Context.initAppNotifierService() { @@ -56,6 +57,10 @@ fun Context.isPlayStoreInstalled() = try { false } +fun getPlayStoreLaunchIntent(packageName: String) = Intent(Intent.ACTION_VIEW).apply { + data = "https://play.google.com/store/apps/details?id=$packageName".toUri() +} + const val FOREGROUND_SERVICE_ID = Integer.MAX_VALUE const val APP_UPDATE_ID = Integer.MAX_VALUE - 1 const val APP_INSTALL_ID = Integer.MAX_VALUE - 2 diff --git a/app/src/main/java/com/farmerbb/appnotifier/ui/SettingsFragment.kt b/app/src/main/java/com/farmerbb/appnotifier/ui/SettingsFragment.kt index ab8f089..0fd9513 100644 --- a/app/src/main/java/com/farmerbb/appnotifier/ui/SettingsFragment.kt +++ b/app/src/main/java/com/farmerbb/appnotifier/ui/SettingsFragment.kt @@ -25,7 +25,6 @@ import android.os.Bundle import android.os.Handler import android.provider.Settings import android.view.View -import androidx.core.net.toUri import androidx.preference.CheckBoxPreference import androidx.preference.ListPreference import androidx.preference.Preference @@ -54,8 +53,7 @@ class SettingsFragment: PreferenceFragmentCompat() { summary = getString(R.string.about_content, calendar.get(Calendar.YEAR)) setOnPreferenceClickListener { - val intent = Intent(Intent.ACTION_VIEW).apply { - data = "market://details?id=${BuildConfig.APPLICATION_ID}".toUri() + val intent = getPlayStoreLaunchIntent(BuildConfig.APPLICATION_ID).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK }