Значок ярлыка на рабочем столе Android не отображается

Я добрался до уровня, на котором я добавляю ярлык через код на домашний экран Android. Я загружаю значок с удаленного сервера, а затем устанавливаю этот значок в качестве ярлыка на домашний экран.

Вот код:

String url = "http://www.the-brights.net/images/icons/brights_icon_50x50.gif";
    InputStream ins = null;

    try {
        ins = new java.net.URL(url).openStream();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Bitmap bm = BitmapFactory.decodeStream(new FlushedInputStream(ins));
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    OutputStream outStream = null;

    try {
        outStream = mContext.openFileOutput("test.png", Context.MODE_PRIVATE);
        bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }


    Log.i("info", "Got here");
    Bitmap bm2;
    try {
        bm2 = BitmapFactory.decodeStream(mContext.openFileInput("test.png"));
        Log.i("info", bm2.toString());

        Intent shortcutIntent = new Intent();
        shortcutIntent.setClassName(mContext, mContext.getClass().getName());
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.putExtra("someParameter", "HelloWorld 123");
        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name 123");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, bm2);
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        mContext.sendBroadcast(addIntent); 
    }
    catch(Exception e) {
        e.printStackTrace();
    }

Проблема в том, что ярлык добавляется, но значок не появляется, отображается значок ярлыка по умолчанию... что я здесь делаю неправильно?


person Maverick    schedule 14.10.2011    source источник


Ответы (1)


Используйте EXTRA_SHORTCUT_ICON вместо EXTRA_SHORTCUT_ICON_RESOURCE, и проблема будет решена.

person Maverick    schedule 10.12.2011