Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, I managed to make the code that works (except it should and cannot work that easily - details are provide bellow).</p> <p>The code that should work is:</p> <pre><code> //create ComponentName for accesing the widget provider ComponentName cn = new ComponentName("com.android.quicksearchbox", "com.android.quicksearchbox.SearchWidgetProvider"); //ComponentName cn = new ComponentName("com.android.music", "com.android.music.MediaAppWidgetProvider"); //get appWidgetManager instance AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getBaseContext()); //get list of the providers - .getAppWidgetIds (cn) does seem to be unrelated to widget hosting and more related to widget development final List&lt;AppWidgetProviderInfo&gt; infos = appWidgetManager.getInstalledProviders(); //get AppWidgetProviderInfo AppWidgetProviderInfo appWidgetInfo = null; //just in case you want to see all package and class names of installed widget providers, this code is useful for (final AppWidgetProviderInfo info : infos) { Log.v("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName()); } //iterate through all infos, trying to find the desired one for (final AppWidgetProviderInfo info : infos) { if (info.provider.getClassName().equals(cn.getClassName()) &amp;&amp; info.provider.getPackageName().equals(cn.getPackageName())) { //we found it appWidgetInfo = info; break; } } if (appWidgetInfo == null) return; //stop here //allocate the hosted widget id int appWidgetId = myWidgetHost.allocateAppWidgetId(); //bind the id and the componentname - here's the problem!!! appWidgetManager.bindAppWidgetId(appWidgetId, cn); //creat the host view AppWidgetHostView hostView = myWidgetHost.createView(getBaseContext(), appWidgetId, appWidgetInfo); //set the desired widget hostView.setAppWidget(appWidgetId, appWidgetInfo); //add the new host view to your activity's GUI LinearLayout ll = (LinearLayout) findViewById(R.id.ll); ll.addView(hostView); </code></pre> <p>Well, the problem is "appWidgetManager.bindAppWidgetId(appWidgetId, cn); " - this requires the permission BIND_APPWIDGET - in the manifest. - even if we put, it still won't work. I read it may be reserved for system applications</p> <p>However, even after adding the permission and putting the apk in the system/app folder, it still does not work (it does not make it a system app).</p> <p>Regarding this problem I found this answer <a href="http://groups.google.com/group/android-developers/browse_thread/thread/231245ba6d1e690f/047b9d3f776d7e54?lnk=gst&amp;q=bindAppWidgetId#047b9d3f776d7e54">here</a>:</p> <blockquote> <p>This is deliberately not available to applications. If you want to add a widget, you need to launch the selector UI for the user to pick the widget which will then take care of the bind. Widgets can expose a lot of private data of all types, so it is not safe to allow an application to arbitrarily bind to them without the user implicitly approving (through the selection UI).</p> <p>Dianne ... Android framework engineer</p> </blockquote> <p>However, I am uncertain but, maybe this means what we could achieve the desired functionality if we could sign the apk with the image developer's key? However, this is off the question's topic. But if you happen to be able to explain to me how to efficiently host AppWidgets, please do and have your answer accepted by me (launcher applications in the market can do it, so it must be possible).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload