首先添加的小部件不可点击。第二是

时间:2012-05-13 10:23:45

标签: android android-widget broadcastreceiver clickable

在我的Broadcastreceiver中,它同时是一个小部件。当我在安装后第一次添加小部件时,它是不可点击的。我添加的第二个小部件是可点击的。虽然第一个小部件仍然无法点击。

在模拟器中测试不同版本时发生此错误。我手边没有其他设备,我可以随时重置。为了进行测试,我总是从“擦除用户数据”开始,以确保它是全新安装。

它适用于1.6,但不适用于2.x

我的偏好设置屏幕是一个手动独立活动,必须以可分离的方式启动。

如果您需要更多信息,请告诉我。

这里是我可以点击的代码:

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    Log.d(LOG_TAG, "Update");
    for (int id : appWidgetIds) {
        Intent intent = new Intent(ACTION);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
        //make widget clickable
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
        remoteViews.setOnClickPendingIntent(R.id.imageview, pendingIntent);
        appWidgetManager.updateAppWidget(id, remoteViews);
    }
}

2 个答案:

答案 0 :(得分:0)

这是一个很长的镜头 - 更改PendingIntent.getBroadcast实例之间的PendingIntent中的请求代码;我认为我的一个小部件遇到了同样的问题,这个改变解决了它。

答案 1 :(得分:0)

我发现了错误。

这是android模拟器别名AVD中的一个错误。该死的东西。希望这有助于其他人不要在非现有错误中浪费那么多时间。

http://code.google.com/p/android/issues/detail?id=8889

bug id 8889“appWidgetManager.updateAppWidget未在2.0,2.1”下更新新AVD上的小部件

解决方法是在开始擦除用户数据之后(我禁用了保存到快照 - 测试未启用)。比退出。比没有擦拭再次开始。 其他写道,您可以使用ctrl + F11两次更改为横向模式并返回。