Android 如何获取appwidget的位置?

Android 如何获取appwidget的位置?,android,android-appwidget,Android,Android Appwidget,我想知道appwidget在屏幕上的位置,但我不知道怎么做。 我应该使用什么功能? 编辑:我在launcher中找到以下代码: /** * Add a widget to the workspace. * * @param data The intent describing the appWidgetId. * @param cellInfo The position on screen where to create the widget. */ private void comp

我想知道appwidget在屏幕上的位置,但我不知道怎么做。 我应该使用什么功能? 编辑:我在launcher中找到以下代码:

/**
 * Add a widget to the workspace.
 *
 * @param data The intent describing the appWidgetId.
 * @param cellInfo The position on screen where to create the widget.
 */
private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo,
        boolean insertAtFirst) {

    Bundle extras = data.getExtras();
    int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    if (LOGD) d(LOG_TAG, "dumping extras content="+extras.toString());

    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    // Calculate the grid spans needed to fit this widget
    CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
    int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);

    // Try finding open space on Launcher screen
    final int[] xy = mCellCoordinates;
    if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
        if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        return;
    }

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

    LauncherModel.addItemToDatabase(this, launcherInfo,
            LauncherSettings.Favorites.CONTAINER_DESKTOP,
            mWorkspace.getCurrentScreen(), xy[0], xy[1], false);

    if (!mRestoring) {
        sModel.addDesktopAppWidget(launcherInfo);

        // Perform actual inflation because we're live
        launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);

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

        mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
                launcherInfo.spanX, launcherInfo.spanY, insertAtFirst);
    } else if (sModel.isDesktopLoaded()) {
        sModel.addDesktopAppWidget(launcherInfo);
    }
}

这是构建特定于Launcher的小部件信息并保存到数据库,我发现数据库是LauncherModel,在LauncherModel中有一个私有的ArrayList,如果我得到ArrayList,我想我可以得到appwidget的位置,有人能告诉我如何得到它。谢谢。

我发现一个方法是,
intent.getsourceBounds()

您可以通过此链接找到: