Home:ALL Converter>Created Widget Not Showing In Widget List - Android

Created Widget Not Showing In Widget List - Android

Ask Time:2014-09-12T02:46:08         Author:Kanishka Ganguly

Json Formatter

Well, firstly, there are a lot of duplicates on SO regarding this issue but the solutions posted there didn't work for me.
Basic info:

  1. Developing for SDK 19
  2. Using Android Studio for development

Added the following to AndroidManifest.xml

 <receiver
            android:name=".widgetProvider"
            android:icon="@drawable/ic_launcher"
            android:label="Home Automation">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_xml" />
 </receiver>

Added the widgetProvider class to src/main/java/com.xxx.yyy.zzz

package com.xxx.yyy.zzz;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;


    public class widgetProvider extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        // implementation will follow
    }
}

Added the widget_layout.xml to res/layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget"
    android:layout_width="320dp"
    android:layout_height="100dp"
    android:background="@android:color/background_dark"
    android:focusable="true">


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="320dp"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="horizontal"
        android:weightSum="2">

        <Button
            android:id="@+id/fan_widget"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="FAN"
            android:textColor="@android:color/white"
            android:textStyle="bold" />

        <Button
            android:id="@+id/light_widget"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="LIGHT"
            android:textColor="@android:color/white"
            android:textStyle="bold" />

    </LinearLayout>


</RelativeLayout>

And finally, I added the widget_xml.xml to the res/xml folder.

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/widget_layout"
    android:minHeight="72dp"
    android:widgetCategory="home_screen"
    android:minResizeHeight="10dp"
    android:minResizeWidth="10dp"
    android:minWidth="72dp"
    android:resizeMode="none"
    android:updatePeriodMillis="86400000" />

I haven't added any functionality yet because I just wanted to check out the layout, but for some reason, it doesn't show up in the widget list. My phone is running 4.4.4 and I am compiling for 4.4.2. Can't figure out what the issue is here. Please help.

Author:Kanishka Ganguly,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25794912/created-widget-not-showing-in-widget-list-android
yy