Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid launcher widget issue
    text
    copied!<p>I am making my first android launcher based on a stock launcher. I am trying to add widgets onto my main linear layout. But that doesn't work. It doesn't get furter than the onActivityResult() method. Please help me and thanks so much in advance! My code:</p> <pre><code>private static final int REQUEST_CREATE_SHORTCUT = 1; private static final int REQUEST_CREATE_LIVE_FOLDER = 4; private static final int REQUEST_CREATE_APPWIDGET = 5; private static final int REQUEST_PICK_APPLICATION = 6; private static final int REQUEST_PICK_SHORTCUT = 7; private static final int REQUEST_PICK_LIVE_FOLDER = 8; private static final int REQUEST_PICK_APPWIDGET = 9; private static final int REQUEST_PICK_ANYCUT=10; private static final int REQUEST_SHOW_APP_LIST = 11; private static final int REQUEST_EDIT_SHIRTCUT = 12; mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new AppWidgetHost(this, R.id.linearLayout); //Add widgets void selectWidget() { int appWidgetId = this.mAppWidgetHost.allocateAppWidgetId(); Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); addEmptyData(pickIntent); Log.d("addWidgetProcedure", "Starting activity to pick widget"); startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); } void addEmptyData(Intent pickIntent) { ArrayList&lt;AppWidgetProviderInfo&gt; customInfo = new ArrayList&lt;AppWidgetProviderInfo&gt;(); pickIntent.putParcelableArrayListExtra( AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo); ArrayList&lt;Bundle&gt; customExtras = new ArrayList&lt;Bundle&gt;(); pickIntent.putParcelableArrayListExtra( AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras); Log.d("addWidgetProcedure", "AddEmptyData"); }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d("addWidgetProcedure", "inside onActivityResult"); if (resultCode == RESULT_OK ) { Log.d("addWidgetProcedure", "RESULT_OK"); if (requestCode == REQUEST_PICK_APPWIDGET) { Log.d("addWidgetProcedure", "calling configureWidget(data)"); configureWidget(data); } else if (requestCode == REQUEST_CREATE_APPWIDGET) { Log.d("addWidgetProcedure", "calling createWidget(data)"); createWidget(data); } } else if (resultCode == RESULT_CANCELED &amp;&amp; data != null) { Log.d("addWidgetProcedure", "RESULT_CANCELED"); int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); if (appWidgetId != -1) { mAppWidgetHost.deleteAppWidgetId(appWidgetId); } } } private void configureWidget(Intent data) { Bundle extras = data.getExtras(); int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (appWidgetInfo.configure != null) { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); intent.setComponent(appWidgetInfo.configure); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); startActivityForResult(intent, REQUEST_CREATE_APPWIDGET); } else { createWidget(data); } } public void createWidget(Intent data) { Bundle extras = data.getExtras(); int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); AppWidgetHostView hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); hostView.setAppWidget(appWidgetId, appWidgetInfo); linearLayout.addView(hostView); Toast.makeText(getApplicationContext(), "Adding widget", 15).show(); } </code></pre> <p>When i press menu->add widget, it calls the selectWidget() method.</p> <p>All the logcat output from when i press menu->add widget to i have selected one.</p> <pre><code>07-11 14:38:27.178: W/KeyCharacterMap(1751): Bad keycharmap - filesize=32 07-11 14:38:27.178: W/KeyCharacterMap(1751): Error loading keycharmap file '/system/usr/keychars/bravo-keypad.kcm.bin'. hw.keyboards.0.devname='bravo-keypad' 07-11 14:38:27.178: W/KeyCharacterMap(1751): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 07-11 14:38:28.348: D/addWidgetProcedure(1751): AddEmptyData 07-11 14:38:28.348: D/addWidgetProcedure(1751): Starting activity to pick widget 07-11 14:38:28.428: D/addWidgetProcedure(1751): inside onActivityResult </code></pre>
 

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