我想使用下面的代码来获取一个小部件ID,但是getAppWidgetIds总是返回一个空数组,num总是0,什么错误?
谢谢!
public class test extends Activity implements OnTouchListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.....
AppWidgetManager mAppWidgetManager;
AppWidgetHost mAppWidgetHost;
mAppWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());
ComponentName THIS_APPWIDGET =new ComponentName("com.android.music", "com.android.music.MediaAppWidgetProvider");
int[] appWidgetId=mAppWidgetManager.getAppWidgetIds(THIS_APPWIDGET);
int num=appWidgetId.length;
答案 0 :(得分:9)
使用
new ComponentName(context, com.android.music.MediaAppWidgetProvider.class)
代替。