android getAppWidgetIds失败了,有什么不对?

时间:2010-03-19 02:24:18

标签: android

我想使用下面的代码来获取一个小部件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;

1 个答案:

答案 0 :(得分:9)

使用

new ComponentName(context, com.android.music.MediaAppWidgetProvider.class)

代替。