Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] App inexplicavelmente colocando 2 atalhos na home ao ser executado

Como está declarado a MainActivity no Manifest? 
Não sei se é o seu caso, mas o que cria icones é o atributo:

<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Caso duas activities tenham esse atributo, ele cria dois icones.

Abraços e boa sorte ai

Att,
Rafael de Araújo

2015-08-13 21:23 GMT-03:00 Matheus Henrique da Silva <matheustargaryen@gmail.com>:
Cara, eu fico maluco com essas coisas. Eu leio o codigo 50 vezes e não consigo entender como acontece umas desgraça dessas...

Era pro app colocar um atalho na home logo depois da primeira execução, mas eu não sei como e muito menos porquê esse maldito esta colocando 2 atalhos idênticos e de uma vez só na home ao ser executado pela primeira vez.

Este é o meu método que cria o atalho:

private void addShortcut() {

        Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        shortcutIntent.putExtra("duplicate", false);
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.mipmap.ic_launcher));
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), MainActivity.class));
        getApplicationContext().sendBroadcast(shortcutIntent);

    }

No fim do onCreate() eu faço a verificação para chamar ou não o método:

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

        if (!pref.contains(KEY_FIRST_RUN)) {

            addShortcut();

            SharedPreferences.Editor editor = pref.edit();

            editor.putBoolean(KEY_FIRST_RUN, true);

            editor.commit();
        }

Desânimo, é só o que parece resultar em ser programador.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário