Can I add widgets from installed apps to my application activity

孤者浪人 提交于 2019-12-04 12:58:04

Finally I solved the issue by using the below code

mAppWidgetManager = AppWidgetManager.getInstance(this);
        mAppWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
        int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
        ComponentName name = new ComponentName("com.android.deskclock","com.android.alarmclock.AnalogAppWidgetProvider");

        int [] ids = mAppWidgetManager.getAppWidgetIds(name);

        if(ids != null && ids.length>0){
            System.err.println("Number of widget ids :"+ids.length);
            AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(ids[0]);
            appWidgetId = ids[0];
            LinearLayout parent= (LinearLayout) findViewById(R.id.generalDashboardLayout);
            parent.addView(mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo));
        }else{
            System.err.println("Ids is null");
        }

Yes you can. You need to make use of AppWidgetHost class, just like all the Home Screen applications does.

Here's a source code home screen app that you can use to learn how to use it. http://code.google.com/p/android-launcher-plus/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!