Getting widget ids from GetAppWidgetIds returning zero

Hey folks, I'm trying to get all widget ids associated with my widget (but I always get 0), called from a service like so:

    var manager = AppWidgetManager.GetInstance(context);
    var componentName = new ComponentName(context.PackageName, typeof(StandardWidget).Name);
    var appWidgetIds = manager.GetAppWidgetIds(componentName);

    StandardWidget.UpdateWidgets(context, appWidgetIds);

My widget is declared like so (am I correct that doing it this way I don't have to declare it in the manifest??):

    [BroadcastReceiver(Label = "Label name here")]
        [IntentFilter(new string [] { "android.appwidget.action.APPWIDGET_UPDATE", "android.appwidget.action.APPWIDGET_ENABLED", "android.appwidget.action.ACTION_APPWIDGET_PICK" })]
    [MetaData("android.appwidget.provider", Resource = "@xml/widget_standard_info")]
    public class StandardWidget : AppWidgetProvider

The reason I'm doing this is because UpdateWidgets is a static method and I'm updating my widget from service so I can't get the type of the widget using the this keyword. I've tried writing the namespace by hand (with and without the 'com'), to no avail, what am I missing?

My context is defined as follows (using mvvmcross):

    _context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity.ApplicationContext;

Thanks!

Answers

  • Jean-FrancoisPineroJean-FrancoisPinero CAMember ✭✭

    Seems this works directly from my widget class (changed the Class.Name):

        var manager = AppWidgetManager.GetInstance(context);
        var componentName = new ComponentName(context.PackageName, Class.Name);
        var appWidgetIds = manager.GetAppWidgetIds(componentName);
    

    And here the class name is:

        Name    "md553c7b0e903aa43c4ad50bfb862d963d6.StandardWidget"    string
    

    How would I replicate the 'Class.Name' in my service method?

  • @Jean-FrancoisPinero said:
    Seems this works directly from my widget class (changed the Class.Name):

      var manager = AppWidgetManager.GetInstance(context);
      var componentName = new ComponentName(context.PackageName, Class.Name);
      var appWidgetIds = manager.GetAppWidgetIds(componentName);
    

    And here the class name is:

      Name    "md553c7b0e903aa43c4ad50bfb862d963d6.StandardWidget"    string
    

    How would I replicate the 'Class.Name' in my service method?

    this is working for me
    Java.Lang.Class.FromType(typeof(StandardWidget)).Name

Sign In or Register to comment.