lorsque nous cliquons sur le widget à ce moment-là, j'ai besoin d'ouvrir un écran d'activité (ou une application) .Comment faire?comment ouvrir une application à partir du widget dans Android?
Répondre
Vous devez définir un onClickpendingIntent sur votre widget
Intent intent = new Intent(context, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.appwidget_provider_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
Check this out
Les pages de développeurs Android pour App Widgets a des informations et un exemple complet faisant exactement ceci: http://developer.android.com/guide/topics/appwidgets/index.html
Incluez ce code dans la méthode onUpdate() de la classe WidgetProvider.
for(int j = 0; j < appWidgetIds.length; j++)
{
int appWidgetId = appWidgetIds[j];
try {
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setComponent(new ComponentName("your Application package",
"fully qualified name of main activity of the app"));
PendingIntent pendingIntent = PendingIntent.getActivity(
context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
layout id);
views.setOnClickPendingIntent(view Id on which onclick to be handled, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
} catch (ActivityNotFoundException e) {
Toast.makeText(context.getApplicationContext(),
"There was a problem loading the application: ",
Toast.LENGTH_SHORT).show();
}
}
Works Amazing! Merci Shivanand Darur –
"votre paquet d'application", "nom complet de l'activité principale de l'application" signifie 'intent.setComponent (nouveau ComponentName (context.getPackageName(), MainActivity.class.getName())' –
- 1. Comment lancer l'activité à partir du widget écran d'accueil Android
- 2. Donne à mon application Android une option de widget
- 3. Android: Faire un appel à partir du widget écran d'accueil
- 4. Android - Appel Activité du widget
- 5. Paquet de plus de 1 widget dans une application Android
- 6. Android: URL spéciale pour ouvrir Marketplace à une application spécifique?
- 7. Comment ajouter un widget Android à mon application?
- 8. Android - accéder à un élément du widget
- 9. Comment autoriser correctement un Widget par opposition à une application?
- 10. Android - mise à jour du texte widget
- 11. Android Ouvrir le menu à partir d'un bouton
- 12. Comment ouvrir une nouvelle page à partir du code derrière?
- 13. Intercepter les liens du navigateur pour ouvrir mon application Android
- 14. Ouvrir/fermer une application winform à partir d'ASP.NET
- 15. Comment ouvrir le document MSWord dans notre application Android
- 16. Comment ouvrir une page Web dans une application BlackBerry?
- 17. Ouvrir application de messagerie à partir de mon application
- 18. ouvrir une application WPF à partir de l'application winforms
- 19. Widget GWT à partir du HTML
- 20. Android - Comment lancer une activité à partir d'un widget et revenir à l'écran d'accueil
- 21. Comment exécuter une commande système à partir d'une application android
- 22. Comment envoyer/ouvrir des pièces jointes à partir d'une application Android?
- 23. Comment ouvrir un dossier à partir d'une application Air 2.0?
- 24. Comment puis-je ajouter un graphique à mon application, comme celui du widget Génie météo Android?
- 25. Comment afficher l'image dans l'arrière-plan du widget android?
- 26. Comment ouvrir appStore à partir du lien web?
- 27. Affichage du calendrier dans une application Android
- 28. Comment puis-je ouvrir une autre application à partir de mon application?
- 29. Comment personnaliser le widget Spinner dans Android?
- 30. Android - Comment faire fonctionner une autre application
Premier lien mort. –
Question secondaire, pouvez-vous extraire des activités pour une application spécifique? (peut-être je ne sais pas quelle classe est ExampleActivity.class) – RelativeGames