Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android appwidget not showing

Looked like my #$#%$%#$ the receiver was not i application element in manifest

Hi

I just created the helloworld appwidget to see how its works. i followed the dev example on adroid dev site. But for some reason the widget does not want to show in the widget list.

AndroidManifest.xml

 <receiver android:name="VoiceRIAWidget" android:label="Voice RIA">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/appwidget_info" />
    </receiver>

appwidget_info.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="Voice RIA" android:minWidth="50dp" android:minHeight="50dp"
    android:updatePeriodMillis="86400000" android:initialLayout="@layout/appwidget">
</appwidget-provider>

VoiceRIAWidget

public class VoiceRIAWidget extends AppWidgetProvider
{

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds)
    {

        final int N = appWidgetIds.length;

        for (int i = 0; i < N; i++)
        {
            int appWidgetId = appWidgetIds[i];

            CharSequence text = "Hello";

            RemoteViews views = new RemoteViews(context.getPackageName(),
                    R.layout.appwidget);

            views.setTextViewText(R.id.appwidget_text, text);

            appWidgetManager.updateAppWidget(appWidgetId, views);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }
}

appwidget.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/appwidget_text" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="#ff000000" />

I cant see what i am missing it runs but nothing in list.

like image 607
Pintac Avatar asked Aug 05 '10 08:08

Pintac


2 Answers

I just had the same problem. My mistake was, that i put the receiver tag just inside my manifest tag, when i was supposed to put it inside my application-tag. This was my not-working-XML:

<manifest....>
  ....
  <receiver ...>
    ...
  </receiver>
  <application ...>
    ...
  </applciation>
</manifest>

This is my well-working-XML:

<manifest...>
  ....
  <application...>
    ...
    <receiver...>
      ...
    </receiver>
  </application>    
</manifest>

Hope it helps you!

like image 64
Pascal Klein Avatar answered Sep 19 '22 11:09

Pascal Klein


I just had the same problem. My mistake was, that I building an app widget as addition to an existing app which was installed on sd-card. Moving the app to phone fixed it.

like image 21
Rene Avatar answered Sep 21 '22 11:09

Rene