use*_*911 3 android android-widget android-appwidget
我正在为我的应用程序开发一个小部件,但有一个问题:
我的 android.widget.RemoteViewsService 类的 onGetViewFactory 方法没有被调用!
我的代码:
意向服务
this.views = new RemoteViews(this.ctx.getPackageName(), i);
Intent localIntent = new Intent(this.ctx, MyWidgetService.class);
localIntent.putExtra("WidgetId", param);
localIntent.setData(Uri.parse(localIntent.toUri(Intent.URI_INTENT_SCHEME)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
this.views.setRemoteAdapter(R.id.weather_list, localIntent);
else
this.views.setRemoteAdapter(param, R.id.weather_list, localIntent);
ComponentName localComponentName = new ComponentName(this.ctx, MyWidgetProvider.class);
AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this.ctx);
localAppWidgetManager.notifyAppWidgetViewDataChanged(param, R.id.weather_list);
localAppWidgetManager.updateAppWidget(param, this.views);
Run Code Online (Sandbox Code Playgroud)
我的小部件服务
我的类扩展了 RemoteViewsService 并具有以下代码
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
// TODO Auto-generated method stub
System.out.println("test");
return null;
}
Run Code Online (Sandbox Code Playgroud)
MyWidgetProvider 我的类扩展了 AppWidgetProvider
有谁能够帮助我?我的代码有什么问题吗?
谢谢 :-)
编辑:是的,但是当我放置断点或日志时,它是相同的。
您已在 宣布服役AndroidManifest.xml吗?
<service
android:name="com.mypackage.MyWidgetService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" >
</service>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2049 次 |
| 最近记录: |