Этот человек был великодушен достаточно добавить свой код к своему вопросу. Но я не могу понять, где взять следующие переменные:
res
, app_id
и p
в
BitmapDrawable bd = (BitmapDrawable) (res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Вот его код:
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(ai.packageName, ai.name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Bitmap newbit;
newbit=bd.getBitmap();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
Кроме того, есть ли что-нибудь, что я должен добавить в файл манифеста?
РЕДАКТИРОВАТЬ:
я заменяю
BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Bitmap newbit;
newbit=bd.getBitmap();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);
с участием
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.launcher_icon));
и это все еще не работает. Вот почему я задаюсь вопросом о файле манифеста.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
, но это может быть не единственная ваша проблема - person Michael Butscher   schedule 27.06.2013