2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/11183: Redirect user to homescreen after widget added

Co-authored-by:  hakkikaancaliskan <caliskanhkaan@gmail.com>
This commit is contained in:
Sawyer Blatz 2020-06-17 14:17:33 -07:00 committed by Emily Kager
parent c6a8a6ed28
commit 65ca7c9cd1

View File

@ -4,6 +4,7 @@
package org.mozilla.gecko.search
import android.app.ActivityManager
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH
@ -36,6 +37,21 @@ class SearchWidgetProvider : AppWidgetProvider() {
override fun onEnabled(context: Context) {
context.settings().addSearchWidgetInstalled(1)
if (isAppInForeground(context)) {
val goHomeOnWidgetAdded = Intent(Intent.ACTION_MAIN)
goHomeOnWidgetAdded.addCategory(Intent.CATEGORY_HOME)
goHomeOnWidgetAdded.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(goHomeOnWidgetAdded)
}
}
// We need this because user can not add widget via launcher app without this
private fun isAppInForeground(context: Context): Boolean {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val runningAppProcesses =
activityManager.runningAppProcesses ?: return false
return runningAppProcesses.any { it.processName == context.packageName &&
it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND }
}
override fun onDeleted(context: Context, appWidgetIds: IntArray) {