Bug 1392224 - Make Fennec the default handler for Leanplum Push Notification. r=maliu

MozReview-Commit-ID: GiXHPvcPhgp

--HG--
extra : rebase_source : f0ca0874c693bccd98b23f0dc83567309d9dfcc1
This commit is contained in:
Nevin Chen 2017-08-22 13:40:17 +08:00
Родитель 7210bd7226
Коммит a873a62c28
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -475,13 +475,21 @@ public class LeanplumPushService {
* Checks if there is some activity that can handle intent.
*/
private static Boolean activityHasIntent(Context context, Intent deepLinkIntent) {
final int flag;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
flag = PackageManager.MATCH_ALL;
} else {
flag = 0;
}
List<ResolveInfo> resolveInfoList =
context.getPackageManager().queryIntentActivities(deepLinkIntent, 0);
context.getPackageManager().queryIntentActivities(deepLinkIntent, flag);
if (resolveInfoList != null && !resolveInfoList.isEmpty()) {
for (ResolveInfo resolveInfo : resolveInfoList) {
if (resolveInfo != null && resolveInfo.activityInfo != null &&
resolveInfo.activityInfo.name != null) {
if (resolveInfo.activityInfo.name.contains(context.getPackageName())) {
// In local build, Fennec's activityInfo.packagename is org.mozilla.fennec_<device_name>
// But activityInfo.name is org.mozilla.Gecko.App. Thus we should use packagename here.
if (resolveInfo.activityInfo.packageName.equals(context.getPackageName())) {
// If url can be handled by current app - set package name to intent, so url will be
// open by current app. Skip chooser dialog.
deepLinkIntent.setPackage(resolveInfo.activityInfo.packageName);