ストックランチャーに基づいて、最初のアンドロイドランチャーを作成しています。メインの線形レイアウトにウィジェットを追加しようとしています。しかし、それはうまくいきません。onActivityResult() メソッドより先には進みません。私を助けてください、そして前もってどうもありがとう!私のコード:
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<AppWidgetProviderInfo> customInfo =
new ArrayList<AppWidgetProviderInfo>();
pickIntent.putParcelableArrayListExtra(
AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
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 && 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();
}
menu->add widget を押すと、selectWidget() メソッドが呼び出されます。
menu-> add widget to iを押したときのlogcat出力はすべて、1つを選択しました。
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