将keyguard默认的时间ClockView替换为digitalClock Appwidget
时间:10-02
整理:3721RD
点击:
1. 按如下方法修改KeyguardHostView.java中addDefaultStatusWidget():
private void addDefaultStatusWidget(int index) {
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
new
ComponentName("com.android.deskclock","com.android.alARMclock.DigitalAppWi
dgetProvider"));
AppWidgetProviderInfo appWidgetInfo =
mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidgetInfo != null) {
AppWidgetHostView view = getAppWidgetHost().createView(mContext,
appWidgetId, appWidgetInfo);
addWidget(view, index);
Log.d(TAG,"keyguardHostView.addDefaultStatusWidget().appWidgetId="+appWidg
etId+"; pageIndex="+index+";"+"appWidgetInfo="+appWidgetInfo);
}
}
2. 如何替换为其他appWidget
只需要将上面bindAppWidgetIdIfAllowed()第二个参数ComponentName修改为对应
appWidget的ComponentName即可
private void addDefaultStatusWidget(int index) {
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
new
ComponentName("com.android.deskclock","com.android.alARMclock.DigitalAppWi
dgetProvider"));
AppWidgetProviderInfo appWidgetInfo =
mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidgetInfo != null) {
AppWidgetHostView view = getAppWidgetHost().createView(mContext,
appWidgetId, appWidgetInfo);
addWidget(view, index);
Log.d(TAG,"keyguardHostView.addDefaultStatusWidget().appWidgetId="+appWidg
etId+"; pageIndex="+index+";"+"appWidgetInfo="+appWidgetInfo);
}
}
2. 如何替换为其他appWidget
只需要将上面bindAppWidgetIdIfAllowed()第二个参数ComponentName修改为对应
appWidget的ComponentName即可