1.将widget预置到launcher首页的布局中去,每一个widget都要进行如下操作,bindAppWidgetIdIfAllowed不可缺少。 int appWidgetId = appWidgetHost.allocateAppWidgetId(); AppWidgetHostView hostView = appWidgetHost.createView(getApplicationContext(), appWidgetId, widgetInfo); hostView.setAppWidget(appWidgetId, widgetInfo); hostViews.add(hostView); Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); Boolean sucess = appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, widgetInfo.provider, options); 2.widget无法跳入app,首先看widget是否进行绑定操作bindAppWidgetIdIfAllowed。再者注意打包时一定要注意用系统对应的签名进行打包。 3.提示无法添加微件时,注意这里的第一个参数上下文要用getApplicationContext()而不能用this。 AppWidgetHostView hostView = appWidgetHost.createView(getApplicationContext(), appWidgetId, widgetInfo);
自定义launcher预置widget无法跳入app,显示无法添加微件问题
最新推荐文章于 2024-07-05 11:38:52 发布