Check Widget is Placed on Android Screen

后端 未结 4 1237
广开言路
广开言路 2020-12-15 10:01

Can someone tell me how to check that my widget have been placed on the homescreen?

I have some code in my app that should run only if the widget is placed on the ho

4条回答
  •  感情败类
    2020-12-15 10:49

    Just saying, but...

        int ids[] = AppWidgetManager.getInstance(this).getAppWidgetIds(new ComponentName(this,MyAppWidgetProvider.class));
    
        Toast.makeText(this, "Number of widgets: "+ids.length, Toast.LENGTH_LONG).show();
    

提交回复
热议问题