gpt4 book ai didi

android - AppWidgets 在自定义启动器中不起作用

转载 作者:行者123 更新时间:2023-11-29 02:00:58 26 4
gpt4 key购买 nike

我在编写启动器时遇到了 appwidgets 的问题。只有 Clock widget 正常工作,其他不正常: Android widgets problem

部分代码:

final AppWidgetHostView hostView = mAppWidgetHost.createView(this, appWidgetId, providerInfo);

if (providerInfo.configure != null) {
// Launch over to configure widget, if needed
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.setComponent(providerInfo.configure);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
mAppWidgetProviderInfo = providerInfo;

startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
} else {
// Otherwise just add it
completeAddAppWidget(appWidgetId, info.container, info.screen, providerInfo);

// Exit spring loaded mode if necessary after adding the widget
exitSpringLoadedDragModeDelayed(true, false);
}

completeAddAppWidget 方法:

private void completeAddAppWidget(final int appWidgetId, long container,
int screen, AppWidgetProviderInfo providerInfo) {
// Calculate the grid spans needed to fit this widget
CellLayout layout = getCellLayout(container, screen);

int[] spanXY = getSpanForWidget(providerInfo, null);

// Try finding open space on Launcher screen
// We have saved the position to which the widget was dragged-- this
// really only matters
// if we are placing widgets on a "spring-loaded" screen
int[] cellXY = mTmpAddItemCellCoordinates;
int[] touchXY = mPendingAddInfo.dropPos;
boolean foundCellSpan = false;
if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
cellXY[0] = mPendingAddInfo.cellX;
cellXY[1] = mPendingAddInfo.cellY;
foundCellSpan = true;
} else if (touchXY != null) {
// when dragging and dropping, just find the closest free spot
int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1],
spanXY[0], spanXY[1], cellXY);
foundCellSpan = (result != null);
} else {
foundCellSpan = layout
.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
}

if (!foundCellSpan) {
if (appWidgetId != -1) {
// Deleting an app widget ID is a void call but writes to disk
// before returning
// to the caller...
new Thread("deleteAppWidgetId") {
public void run() {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
}
}.start();
}
showOutOfSpaceMessage();
return;
}

// Build Launcher-specific widget info and save to database
LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(
appWidgetId);
launcherInfo.spanX = spanXY[0];
launcherInfo.spanY = spanXY[1];

LauncherModel.addItemToDatabase(this, launcherInfo, container, screen,
cellXY[0], cellXY[1], false);

if (!mRestoring) {
// Perform actual inflation because we're live
launcherInfo.hostView = mAppWidgetHost.createView(this,
appWidgetId, providerInfo);

launcherInfo.hostView.setAppWidget(appWidgetId, providerInfo);
launcherInfo.hostView.setTag(launcherInfo);

mWorkspace.addInScreen(launcherInfo.hostView, container, screen,
cellXY[0], cellXY[1], launcherInfo.spanX,
launcherInfo.spanY, isWorkspaceLocked());

addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, providerInfo);
}
}

最佳答案

我前阵子遇到过这个问题。您必须在每次应用程序小部件更改、添加删除等后调用 startListening()。

关于android - AppWidgets 在自定义启动器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12648237/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com