重置手机后Android小部件应用程序中的按钮不工作

重置手机后Android小部件应用程序中的按钮不工作,android,button,widget,reset,boot,Android,Button,Widget,Reset,Boot,我有一个小部件在一个按钮。我想在onClick中更改此按钮的颜色。一切正常,但当我重新启动手机时,小部件无法正常工作(按钮不改变颜色)。当我删除小部件并再次添加时,一切正常 AppWidgetProvider类: package com.as.mateusz.smartlinegsm; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.App

我有一个小部件在一个按钮。我想在
onClick
中更改此
按钮的颜色。一切正常,但当我重新启动手机时,
小部件
无法正常工作(
按钮
不改变颜色)。当我删除
小部件
并再次添加时,一切正常

AppWidgetProvider
类:

package com.as.mateusz.smartlinegsm;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;



public class SmartLineWidget extends AppWidgetProvider {

    public static final String MY_TAG = "Widget Message: ";
    // our actions for our buttons
    public static String ACTION_WIDGET_BUTTONW1 = "ActionReceiverButtonW1";


    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,  int[] appWidgetIds) {
        Log.i(MY_TAG, "WIDGET onUpdate");
        Toast.makeText(context, "Widget: onUpdate" , Toast.LENGTH_LONG).show();


        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.smart_line_widget);

        Intent active = new Intent(context, SmartLineWidget.class);
        active.setAction(ACTION_WIDGET_BUTTONW1);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
        remoteViews.setOnClickPendingIntent(R.id.buttonW1, actionPendingIntent);


        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    }

    @Override
    public void onReceive(Context context, Intent intent) {

        super.onReceive(context, intent);

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


        Log.i(MY_TAG, "WIDGET onRecive");



        if (intent.getAction().equals(ACTION_WIDGET_BUTTONW1)) {
             views.setInt(R.id.buttonW1, "setBackgroundResource", button_off);
             Log.i(MY_TAG, "W1 true");
        } 

        AppWidgetManager mgr = AppWidgetManager.getInstance(context);
        ComponentName me = new ComponentName(context, SmartLineWidget.class);
        mgr.updateAppWidget(me, views);

    }



    @Override
    public void onEnabled(Context context) {
        // Enter relevant functionality for when the first widget is created

        Toast.makeText(context, "Widget: onEnabled" , Toast.LENGTH_LONG).show();

        super.onEnabled(context);
    }


    @Override
    public void onDisabled(Context context) {
        // Enter relevant functionality for when the last widget is disabled
        Log.i(MY_TAG, "WIDGET onDisable Event");
    }
}
并表明:

<receiver android:name=".SmartLineWidget"
            android:label="SmartLineGSM Widget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="com.as.mateusz.smartlinegsm.ACTION_WIDGET_RECEIVER"/>
                <action android:name="org.divenvrsk.widgets.ExampleProvider.ACTION_WIDGET_BUTTONW1" />
            </intent-filter>

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