Widget pinning not working with Android Huawei and Vivo devices

737 Views Asked by At

I developed an app that can pin widgets to the home screen, it works perfectly on most devices, but not with Huawei and Vivo phones.

When I pin a widget with a Huawei/Vivo device by calling appWidgetManager.requestPinAppWidget() then it will invoke the configuration screen as defined in the android:configure field of the appwidget-provider. Once I confirm the configuration, settings are saved properly, but Huawei/Vivo launcher shows an error and does not load the widget (and the error is not related to my app!).

I also tried to create another appwidget-provider without the android:configure parameter, and it works perfectly on Huawei phones (but not working on Vivo!). However, Android will show another widget on the launcher’s widget selection screen (i.e. the widget picker). If I use android:widgetFeatures=hide_from_picker it will work only from Android API 28+, and older devices will still see a “wrong” widget option that cannot be configured (note: Huawei phones will simply ignore that options, even if they are API 28+).

Any way I can fix the widget pinning on Huawei phones, Vivo phones, or devices that behave like that?

UPDATE: at present I decided to disable the widget pinning feature when Build.MANUFACTURER.toLowerCase() is either "vivo" or "huawei".

UPDATE 2: I tested with Nova Launcher, and appWidgetManager.requestPinAppWidget() works perfectly also with Huawei and Vivo devices, thus it is their default Launcher which is buggy... :(

1

There are 1 best solutions below

0
On

This is not the fix to the issue, but I ended up disabling appWidgetManager.requestPinAppWidget() functionality for devices using Vivo and Huawei default launchers in the following way:

  1. Add to your manifest:
 <queries>
     <intent>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.HOME" />
     </intent>
 </queries>
  1. Use this method to detect if the current default launcher supports or not widget pinning:

       private static boolean isUsingSupportedLauncher(Context context) {
    
         PackageManager packageManager = context.getPackageManager();
         Intent intent = new Intent(Intent.ACTION_MAIN);
         intent.addCategory(Intent.CATEGORY_HOME);
         String pname = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
    
         // Huawei launcher is not supported for widget pinning
         if (TextUtils.equals(pname, "com.huawei.android.launcher"))
            return false;
    
         // Vivo and Nokia-Go launcher is not supported for widget pinning
         if (TextUtils.equals(pname, "com.android.launcher3"))
            return false;
    
         return true;
    
       }
    

Note: more tech-savvy users that use a third-party launcher can still enjoy the widget-pinning feature on Huawei and Vivo devices, the rest will have to add widget(s) from the launcher itself...