'How to lauch APK installation from notification?
Hello :) I want to launch APK installation by clicking the notification. I have already implemented file download and after that notification appears but if I click on such notification.... nothing happens. Here is my code for the notification
private fun showUpdateReadyToInstallNotification(file: File) {
val intent = Intent(Intent.ACTION_VIEW);
intent.setDataAndType(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file), "application/vnd.android.package-archive")
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
val notificationBuilder = NotificationCompat.Builder(this, "UPDATE_CHANNEL")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Update")
.setContentText("Your Update is Downloaded and ready to install! Press This notification to install")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationChannel = NotificationChannel("UPDATE_CHANNEL", "Update", NotificationManager.IMPORTANCE_HIGH)
notificationManager.createNotificationChannel(notificationChannel)
notificationManager.notify(100, notificationBuilder.build())
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
