Lockscreen widget not working on Android 4.2

Well, I have an application in which there is widget. It perfectly works in notification shade and it works on lickscreen in android 5. But I can't figure out how to make it work on android 4.2 lockscreen. Help me please

Here is my BroadcastReceiver code:

[BroadcastReceiver(Label = "@string/widget_name", Enabled = true, Name = "ru...WordWidget")]
[IntentFilter(new string[] { Helper.ActionClear, Helper.ActionPlus, Helper.ActionMute, Android.Appwidget.AppWidgetManager.ActionAppwidgetUpdate })]
[MetaData("android.appwidget.provider", Resource = "@xml/widget_word")]
public class WordWidget : AppWidgetProvider
{
static int counter = 0;
static RemoteViews updatedViews;
static AppWidgetManager managerWidget;
static int[] appWidgetIds;

static Intent intent = null;

#region OnReceive
string GetCounter()
{
    string res = WordWidget.counter < 10 ? "00" + WordWidget.counter.ToString() :
        WordWidget.counter < 100 ? "0" + WordWidget.counter.ToString() :
        WordWidget.counter.ToString();

    return res;
}
public override void OnReceive(Context context, Intent intent)
{
    try
    {
        WordWidget.managerWidget = AppWidgetManager.GetInstance(context);
        ComponentName thisWidget = new ComponentName(context, "ru...WordWidget");
        WordWidget.appWidgetIds = WordWidget.managerWidget.GetAppWidgetIds(thisWidget);

        CreateViews(context);

        switch (intent.Action)
        {
            // some code ...
        }
    }
    catch (Exception ex) { Log.Error("WordWidget.OnReceive", ex.Message); }

    base.OnReceive(context, intent);
}
#endregion

#region CreateViews
void CreateViews(Context context)
{
    WordWidget.updatedViews = new RemoteViews("ru...shams", Resource.Layout.widget);
    WordWidget.updatedViews.SetTextViewText(Resource.Id.wText, GetCounter());

    // Clear button
    WordWidget.intent.SetAction(Helper.ActionClear);
    PendingIntent actionPendingIntent = PendingIntent.GetBroadcast(context, 0, WordWidget.intent, PendingIntentFlags.UpdateCurrent);
    WordWidget.updatedViews.SetOnClickPendingIntent(Resource.Id.wbutton2, actionPendingIntent);

    // +1 button
    WordWidget.intent.SetAction(Helper.ActionPlus);
    PendingIntent actionPendingIntent2 = PendingIntent.GetBroadcast(context, 0, WordWidget.intent, PendingIntentFlags.UpdateCurrent);
    WordWidget.updatedViews.SetOnClickPendingIntent(Resource.Id.wbutton1, actionPendingIntent2);

    // mute button
    WordWidget.intent.SetAction(Helper.ActionMute);
    PendingIntent actionPendingIntent3 = PendingIntent.GetBroadcast(context, 0, WordWidget.intent, PendingIntentFlags.UpdateCurrent);
    WordWidget.updatedViews.SetOnClickPendingIntent(Resource.Id.wbutton3, actionPendingIntent3);


    WordWidget.managerWidget.UpdateAppWidget(WordWidget.appWidgetIds, WordWidget.updatedViews);
}
#endregion

#region OnUpdate
public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{

    WordWidget.managerWidget = AppWidgetManager.GetInstance(context);
    ComponentName thisWidget = new ComponentName(context, "ru...WordWidget");
    WordWidget.appWidgetIds = WordWidget.managerWidget.GetAppWidgetIds(thisWidget);

    CreateViews(context);
}
#endregion

}

here are my .xml, .axml and .cs files for widget http://1drv.ms/1Pgo61T

Tagged:
Sign In or Register to comment.