Bug 1312686 - Link "default browser" setting to app info screen on Android 7+; r?sebastian
Added support for changing default browser by opening settings screen in API Levels >=24.
MozReview-Commit-ID: 5rxJm6hQQ4A
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -47,16 +47,17 @@ public class AppConstants {
* If MIN_SDK_VERSION is greater than or equal to the number, there
* is no need to do the runtime check.
*/
public static final boolean feature16Plus = MIN_SDK_VERSION >= 16 || (MAX_SDK_VERSION >= 16 && Build.VERSION.SDK_INT >= 16);
public static final boolean feature17Plus = MIN_SDK_VERSION >= 17 || (MAX_SDK_VERSION >= 17 && Build.VERSION.SDK_INT >= 17);
public static final boolean feature19Plus = MIN_SDK_VERSION >= 19 || (MAX_SDK_VERSION >= 19 && Build.VERSION.SDK_INT >= 19);
public static final boolean feature20Plus = MIN_SDK_VERSION >= 20 || (MAX_SDK_VERSION >= 20 && Build.VERSION.SDK_INT >= 20);
public static final boolean feature21Plus = MIN_SDK_VERSION >= 21 || (MAX_SDK_VERSION >= 21 && Build.VERSION.SDK_INT >= 21);
+ public static final boolean feature24Plus = MIN_SDK_VERSION >= 24 || (MAX_SDK_VERSION >= 24 && Build.VERSION.SDK_INT >= 24);
/*
* If our MIN_SDK_VERSION is 14 or higher, we must be an ICS device.
* If our MAX_SDK_VERSION is lower than ICS, we must not be an ICS device.
* Otherwise, we need a range check.
*/
public static final boolean preMarshmallow = MAX_SDK_VERSION < 23 || (MIN_SDK_VERSION < 23 && Build.VERSION.SDK_INT < 23);
public static final boolean preLollipop = MAX_SDK_VERSION < 21 || (MIN_SDK_VERSION < 21 && Build.VERSION.SDK_INT < 21);
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/LinkPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/LinkPreference.java
@@ -1,35 +1,45 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* 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.gecko.preferences;
-import org.mozilla.gecko.Tabs;
-
import android.content.Context;
+import android.content.Intent;
import android.preference.Preference;
import android.util.AttributeSet;
+import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.Tabs;
+
class LinkPreference extends Preference {
private String mUrl;
public LinkPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mUrl = attrs.getAttributeValue(null, "url");
}
public LinkPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mUrl = attrs.getAttributeValue(null, "url");
}
public void setUrl(String url) {
mUrl = url;
}
+ /**
+ * Open Default apps screen of Settings for API Levels>=24. Support URL will open for lower API levels
+ */
@Override
protected void onClick() {
- Tabs.getInstance().loadUrlInTab(mUrl);
- callChangeListener(mUrl);
+ if (AppConstants.Versions.feature24Plus) {
+ Intent changeDefaultApps = new Intent("android.settings.MANAGE_DEFAULT_APPS_SETTINGS");
+ getContext().startActivity(changeDefaultApps);
+ } else {
+ Tabs.getInstance().loadUrlInTab(mUrl);
+ callChangeListener(mUrl);
+ }
}
}