Skip to content

Commit

Permalink
AppNotifier 1.1 (release 2)
Browse files Browse the repository at this point in the history
* Fix a few crashes reported via Android vitals
  • Loading branch information
farmerbb committed Jan 24, 2020
1 parent 762924f commit 90376e1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {

minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionCode 5
versionName "1.1"

resConfigs "en", "fr"
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/farmerbb/appnotifier/AppNotifierService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/farmerbb/appnotifier/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 90376e1

Please sign in to comment.