Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 小部件中的OnClick和AlarmManager对我不起作用_Android_Android Widget_Android Manifest_Alarmmanager_Android Pendingintent - Fatal编程技术网

Android 小部件中的OnClick和AlarmManager对我不起作用

Android 小部件中的OnClick和AlarmManager对我不起作用,android,android-widget,android-manifest,alarmmanager,android-pendingintent,Android,Android Widget,Android Manifest,Alarmmanager,Android Pendingintent,我有一个使用AlarmManager更新的小部件,它工作正常 <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&

我有一个使用AlarmManager更新的小部件,它工作正常

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
现在我想添加一个onClick事件。我的问题是我从来没有得到过一次机会?或者至少由我的接受者处理

@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;
      for (int i=0; i<N; i++) {
          int appWidgetId = appWidgetIds[i];
          updateAppWidget(context, appWidgetManager, appWidgetId);

          //Toast.makeText(context, "onUpdate(): " + String.valueOf(i) + " : " + String.valueOf(appWidgetId), Toast.LENGTH_LONG).show();
      }

}

public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId){
.
.
.
RemoteViews updateViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout);

updateViews.setTextViewText(R.id.widgettext, "[" + String.valueOf(appWidgetId) + "]" + strWidgetText);


Intent intent = new Intent(context, MyWidgetProvider.class);
intent.setAction(MY_WIDGET_CLICK);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,1, intent, 0);

updateViews.setOnClickPendingIntent(R.id.toggle_button_widget, pendingIntent);  
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
正如你们所看到的,我有一个祝酒词,所以哪个警报被触发了,我只得到我的小部件更新作为行动

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
舱单呢

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>

我是Android新手,因此非常感谢您的帮助;)

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
我猜是我的清单过滤了onClick事件。有人知道您是否可以看到通过Eclipse调试器触发的事件吗

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
/奥利

我真蠢

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
Bug发现,它和Android没有任何关系,只是编程不好

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
我将else if(我的小部件)CLICK.equals(intent.getAction())嵌套在 if(extras!=null)而不是if(MY_WIDGET_UPDATE.equals(intent.getAction())

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
所以剩下的代码都能用!希望我没有把任何人搞糊涂

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>
/奥利

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

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

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>