Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AppWidgetHost widget_host = new AppWidgetHost(this, 1);
- AppWidgetManager widget_manager = AppWidgetManager.getInstance(this);
- int widget_id = widget_host.allocateAppWidgetId();
- AppWidgetProviderInfo widget_provider = ... //from an array;
- Intent bindIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
- bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id);
- bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, widget_provider.provider);
- startActivityForResult(bindIntent, REQUEST_BIND_APPWIDGET);
- if (widget_provider.configure != null) {
- Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
- intent.setComponent(widget_provider.configure);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id);
- startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
- } else {
- createWidget(widget_id);
- }
- Intent bindIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
- bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id);
- bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, widget_provider.provider);
- startActivityForResult(bindIntent, REQUEST_BIND_APPWIDGET);
- Boolean callProviderIntent = false;
- if (checkCallProviderIntent)
- {
- callProviderIntent = true;
- Method m = null;
- try
- {
- m = AppWidgetManager.class
- .getMethod("bindAppWidgetIdIfAllowed", new Class[]
- { Integer.TYPE, ComponentName.class });
- }
- catch (NoSuchMethodException e)
- {
- }
- if (m != null)
- {
- try
- {
- callProviderIntent = !(Boolean) m
- .invoke(mAppWidgetManager,
- appWidgetId,
- launcherAppWidgetInfo.provider);
- }
- catch (Exception e)
- {
- }
- }
- }
- AppWidgetManager manager = m.getAppWidgetManager();
- AppWidgetHost host = m.getWidgetHost();
- List<AppWidgetProviderInfo> widgetList = manager.getInstalledProviders();
- AppWidgetProviderInfo provider = null;
- for(AppWidgetProviderInfo info : widgetList){
- //To get the google search box
- if(info.provider.getClassName().equals("com.google.android.googlequicksearchbox.SearchWidgetProvider")){
- provider = info;
- break;
- }
- }
- if(provider != null){
- int id = host.allocateAppWidgetId();
- boolean success = false;
- success = manager.bindAppWidgetIdIfAllowed(id, provider.provider);
- if (success) {
- AppWidgetHostView hostView = host.createView(getActivity(), id, provider);
- AppWidgetProviderInfo appWidgetInfo = manager.getAppWidgetInfo(id);
- LauncherAppWidgetInfo info = new LauncherAppWidgetInfo(id);
- info.hostView = hostView;
- info.hostView.setAppWidget(id, appWidgetInfo);
- attachWidget(info);
- } else {
- Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER,
- provider.provider);
- // TODO: we need to make sure that this accounts for the options
- // bundle.
- // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS,
- // options);
- m.startActivityForResult(intent, Main.REQUEST_BIND_APPWIDGET);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement