Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Criando atalho/shortcut

Bom dia pessoal,

Revivendo o tópico.
Existe alguma forma de criar o atalho no Homescreen assim que o aplicativo for instalado? 
Ou existe algum broadcastReceiver para interceptar o evento de instalação?

Obrigado


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 15:20, Pedro Subutzki <Pepeu> <falecompepeu@gmail.com> escreveu:
Ótimo!!! :)


Abraços,
Pedro Subutzki
__________________________________________
HADI - Makes SQLite in Android easy and simple
https://github.com/PepeuCps/Hadi


Em 24 de setembro de 2013 14:48, Gerson Felipe <gersongfpn@gmail.com> escreveu:

:)

Atenciosamente,
Gerson Novais


Em 24 de setembro de 2013 14:45, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:

Funcionou assim:
Setei o context = getApplicationContext(); no onCreate;

public void createShortcut(){
               Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");


// Shortcut name
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "nome do atalho");
shortcut.putExtra("duplicate", false); // Just create once

// Setup activity shoud be shortcut object
ComponentName component = new ComponentName(getPackageName(), getClass().getName());

shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
Intent.ACTION_MAIN).setComponent(component));

// Set shortcut icon
ShortcutIconResource iconResource = Intent.ShortcutIconResource .fromContext(context,R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

context.sendBroadcast(shortcut);
}

Igual o Pedro falou, até hoje para mim não havia feito diferença!

Obrigado aos dois pela ajuda! 

Att.


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 14:36, Gerson Felipe <gersongfpn@gmail.com> escreveu:

@Pedro
É isso ae...
Procurando nos meus favoritos aqui de muito tempo atras, encontrei isso aqui para fortalecer mais esse e-mail com conteúdo de qualidade (mesmo que não ajude o amigo ai..) 

  • View.getContext(): Returns the context the view is currently running in. Usually the currently active Activity.

  • Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just the current Activity.

  • ContextWrapper.getBaseContext(): If you need access to a Context from within another context, you use a ContextWrapper. The Context referred to from inside that ContextWrapper is accessed via getBaseContext().



Atenciosamente,
Gerson Novais


Em 24 de setembro de 2013 14:34, Pedro Subutzki <Pepeu> <falecompepeu@gmail.com> escreveu:

@Gerson
Exato. O contexto da aplicação é bem diferente do contexto da aplicação apesar de em muitos lugares isso não fazer tanta diferença.
Porém usar de qualquer jeito sem saber "como" e "pra quê serve" sempre podem trazer problemas. ;)


Abraços,
Pedro Subutzki
__________________________________________
HADI - Makes SQLite in Android easy and simple
https://github.com/PepeuCps/Hadi


Em 24 de setembro de 2013 14:31, Gerson Felipe <gersongfpn@gmail.com> escreveu:

Tente usar o getApplicationContext neste final de código, quando vc faz o BroadCast.

O this retorna o contexto da View, geralmente usado para a Activity atual.

Atenciosamente,
Gerson Novais


Em 24 de setembro de 2013 14:27, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:
estou setando o contexto em onCreate.

private Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
...

Obrigado


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 14:26, Gerson Felipe <gersongfpn@gmail.com> escreveu:

no seu código eu não vi qual é o seu context, como vc está obtendo este context, que vc usa no final do código no broadcast.

Atenciosamente,
Gerson Novais


Em 24 de setembro de 2013 14:19, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:

Bom, Se vc olhar o exemplo no link vai ver que é idêntico ao meu e não funciona.

O segundo eu já havia testado e nem criar o ícone ele cria!

Att.


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 14:10, Gerson Felipe <gersongfpn@gmail.com> escreveu:


Atenciosamente,
Gerson Novais


Em 24 de setembro de 2013 14:08, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:

Eu gostaria que meu aplicativo criasse um ícone/atalho na HomeScreen na primeira vez q fosse executado. 

att.


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 14:05, Pedro Subutzki <Pepeu> <falecompepeu@gmail.com> escreveu:

Carlos,
O que você precisa fazer? Que ícone você quer criar?

Abraços,
Pedro Subutzki
__________________________________________
HADI - Makes SQLite in Android easy and simple
https://github.com/PepeuCps/Hadi


Em 24 de setembro de 2013 13:59, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:

sim, ao meu ponto de vista isso funcionaria para que o ícone fosse criado apenas uma vez na tela não?

Independente do número de vezes que eu chamar o método ele não deveria criar mais ícones. Ou estou enganado?


--
Carlos Eduardo Simões Pelegrin


Em 24 de setembro de 2013 13:54, Pedro Subutzki <Pepeu> <falecompepeu@gmail.com> escreveu:

O "duplicate =  false". Não é isso que você está querendo manter durante a execução?

Abraços,
Pedro Subutzki
__________________________________________
HADI - Makes SQLite in Android easy and simple
https://github.com/PepeuCps/Hadi


Em 24 de setembro de 2013 13:50, Carlos Eduardo <carloseduardopelegrin@gmail.com> escreveu:

Desculpe não entendi,
Qual valor?


--
Carlos Eduardo Simões Pelegrin


2013/9/24 Pedro Subutzki <Pepeu> <falecompepeu@gmail.com>

Já tentou criar uma classe estática pra guardar o valor que você precisa?

Abraços,
Pedro Subutzki
__________________________________________
HADI - Makes SQLite in Android easy and simple
https://github.com/PepeuCps/Hadi


2013/9/24 Carlos Pelegrin <carloseduardopelegrin@gmail.com>
Boa tarde pessoal,

Estou utilizando esse código:

public void createShortcut(){
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getPackageName(), getClass().getName());

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "nome do atalho");
addIntent.putExtra("duplicate", false); //Aqui não funciona
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
}

Bom, tudo legal na primeira execução, mas o putExtra("duplicate", false); não funciona como planejado. 
Se eu abrir o aplicativo 10 vezes, ele cria 10 ícones. 

Estou instanciando o método no onCreate. 

Alguém já passou por esse problema? alguém sabe o motivo disso?


Obrigado

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

--
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/groups/opt_out.

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

0 comentários:

Postar um comentário