Get the size of my homescreen widget

前端 未结 6 2039
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 15:46

I just want to know how big my current widget is. I found tons of questions to set the minimum size, but I don\'t want to set it. Instead I want to show that informations which

6条回答
  •  春和景丽
    2021-02-02 16:20

    For Android 4.1 (API 16) or high:

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance( context );
    int ids[] = appWidgetManager.getAppWidgetIds( componentName );
    for( int id : ids ){
        Bundle options = appWidgetManager.getAppWidgetOptions( id );
        int width = options.getInt (AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
        int height = options.getInt (AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
    }
    

提交回复
热议问题