Widget causes "Application not installed" error

I am trying to create my first Widget for the home screen. I have read the tutorial on the developer site, combed the web for tutorials, tipps and problem solutions but still can't seem to get it to work.

Problem:

I can run the App without any problems. I can also select the Widget for my App from the menu (long click on home screen --> Android-Widgets --> List of available Widgets). When I select my widget though, I get the following error message (as a toast): "Application is not installed on your phone."

Here my source code :

Entry in the manifest:

<receiver android:name=".SubscriberStateWidgetProvider" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

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

AppWidgetInfoProvider xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  android:minWidth="40dp"
  android:minHeight="40dp"
  android:updatePeriodMillis="300000"
  android:configure="de.xxx.SubscriberStateWidgetProvider">
</appwidget-provider>

Layout-File:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="@dimen/widget_margin">
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

      <ImageView
          android:id="@+id/subscriberStateWidgetImage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/acc_app_logo"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_margin="5dp" />
      <TextView 
          android:id="@+id/subscriberStateWidgetTextViewLable"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/subscriberStatusText"
          android:layout_toRightOf="@+id/subscriberStateWidgetImage"
          android:layout_alignTop="@+id/subscriberStateWidgetImage"
          android:layout_marginLeft="5dp"/>

       <TextView 
          android:id="@+id/subscriberStateWidgetTextViewInfo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@+id/subscriberStateWidgetImage"
          android:layout_below="@+id/subscriberStateWidgetTextViewLable"
          android:layout_alignBottom="@+id/subscriberStateWidgetImage"
          android:layout_marginLeft="5dp"
          android:text="@string/subscriberStatusUnknown"/>

  </RelativeLayout>
</FrameLayout>

AppWidgetProvider-Klass:

public class SubscriberStateWidgetProvider extends AppWidgetProvider{

public String SUBSCRIBER_WIDGET_UPDATE = "subscriberWidgetUpdate";


@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    // TODO Auto-generated method stub
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    final int N = appWidgetIds.length;

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int i=0; i<N; i++) {
        int appWidgetId = appWidgetIds[i];
    }
}
}

Possible causes that I have excluded:

  • Double declaration of the launch Activity in the manifest
  • Systax error in widget provider
  • Double permissen declaraion in the manifest
  • Double Widget declaration in the manifest
  • The app is defenetly installed. I can select it from the application menu and it works perfectly.
  • I have also tried creating the widget when the app is running (started app, pushed button to go to home screen) and when app is not running (started app, used back button to stop the app) and get the same behaviour both times.

    There are no error or warning entries in the LogCat or my Log file.

    I would really appriciate any ideas, solutions or help you might have. Thanks in advance!


    Finally got it to work :-) Still not sure, where the problem was though...

    Here is my working source code:

    Entry in manifest:

    <receiver android:name="SubscriberStateWidgetProvider" >
            <intent-filter >
                <action 
                    android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
    
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/subscriber_status_widget" />
        </receiver>
    

    AppWidgetInfoProvider xml:

    <?xml version="1.0" encoding="utf-8"?>
      <appwidget-provider 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:initialLayout="@layout/subscriber_state_widget_layout"
        android:minHeight="72dp"
        android:minWidth="300dp"
        android:updatePeriodMillis="300000" >
      </appwidget-provider>
    

    Layout-File:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dip"
        android:background="@drawable/myshape" >
    
         <TextView
            android:id="@+id/subscriberStateLable"
            style="@android:style/TextAppearance.Medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/widgetImage"
            android:layout_toRightOf="@+id/widgetImage"
            android:gravity="center_horizontal|center_vertical"
            android:layout_margin="4dip"
            android:text="@string/subscriberStatusText" >
        </TextView>
    
        <TextView
            android:id="@+id/update"
            style="@android:style/TextAppearance.Medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/widgetImage"
            android:layout_toRightOf="@+id/widgetImage"
            android:gravity="center_horizontal|center_vertical"
            android:layout_margin="4dip"
            android:text="@string/subscriberStatusUnknown" >
        </TextView>
    </RelativeLayout> 
    

    AppWidgetProvider-Class:

    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
          int[] appWidgetIds) {
    
        // Get all ids
        ComponentName thisWidget = new ComponentName(context,
            SubscriberStateWidgetProvider.class);
        String currentSubscriberState =     SubscriberStatusActivity.getCurrentSubscriberStateAsString(context);
    
        int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
        for (int widgetId : allWidgetIds) {
    
    
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
              R.layout.subscriber_state_widget_layout);
          Log.w("WidgetExample", currentSubscriberState);
          // Set the text
          remoteViews.setTextViewText(R.id.update, currentSubscriberState);
    
          // Register an onClickListener
          Intent intent = new Intent(context, SubscriberStateWidgetProvider.class);
    
          intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
          intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    
          PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
              0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
          remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
          appWidgetManager.updateAppWidget(widgetId, remoteViews);
        }
      }
    
    链接地址: http://www.djcxy.com/p/50588.html

    上一篇: 如何在用户在“今日视图”中启用小部件时以编程方式进行检测

    下一篇: 小部件导致“应用程序未安装”错误