This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1886792 - Handle install_search_widget deeplink r=android-reviewe…
…rs,amejiamarmol Differential Revision: https://phabricator.services.mozilla.com/D205477
- Loading branch information
Showing
4 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
fenix/app/src/main/java/org/mozilla/fenix/utils/AddSearchWidgetPrompt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.utils | ||
|
||
import android.app.Activity | ||
import android.appwidget.AppWidgetManager | ||
import android.content.ComponentName | ||
import android.os.Build | ||
import org.mozilla.fenix.onboarding.WidgetPinnedReceiver | ||
import org.mozilla.gecko.search.SearchWidgetProvider | ||
|
||
/** | ||
* Displays the "add search widget" prompt for capable devices. | ||
* | ||
* @param activity the parent [Activity]. | ||
*/ | ||
fun showAddSearchWidgetPrompt(activity: Activity) { | ||
// Requesting to pin app widget is only available for Android 8.0 and above | ||
if (canShowAddSearchWidgetPrompt()) { | ||
val appWidgetManager = AppWidgetManager.getInstance(activity) | ||
val searchWidgetProvider = | ||
ComponentName(activity, SearchWidgetProvider::class.java) | ||
if (appWidgetManager.isRequestPinAppWidgetSupported) { | ||
val successCallback = WidgetPinnedReceiver.getPendingIntent(activity) | ||
appWidgetManager.requestPinAppWidget(searchWidgetProvider, null, successCallback) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Checks whether the device is capable of displaying the "add search widget" prompt. | ||
*/ | ||
fun canShowAddSearchWidgetPrompt() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters