I have an app and have decided to add a widget to it, I've followed all the official documentation for it, but when I install the app on my Galaxy Nexus, the widget doesn't appear in the app/widget list.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dysign.livetubecountdown"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dysign.livetubecountdown.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.dysign.livetubecountdown.Widget" android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<intent-filter>
<action android:name="android.appwidget,action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" />
</receiver>
</application>
widget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="80dp"
android:minWidth="80dp"
android:minResizeHeight="40dp"
android:minResizeWidth="40dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/widget_main"
android:previewImage="@drawable/ic_launcher"
android:widgetCategory="home_screen"
android:resizeMode="horizontal|vertical">
</appwidget-provider>
widget_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/widgetTextView"/>
</FrameLayout>
Widget.java
package com.dysign.livetubecountdown;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.widget.RemoteViews;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerClass(context, appWidgetManager), 1, 1000);
}
private class TimerClass extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
public TimerClass(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_main);
thisWidget = new ComponentName(context, Widget.class);
}
@Override
public void run() {
remoteViews.setTextViewText(R.id.widgetTextView, "TIME = " +format.format(new Date()));
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
}
}
I've been looking all over the web to try to fix this, but every suggestion I try just doesn't work. Also there are no errors in LogCat or any mention of anything widget related.
Any help is much appreciated, thanks!