Bonjour à tous,
après avoir passer en revu tous le web je me résigne à demander de l'aide !
J'ai développé une petite application type NotePad via une DB, jusque là pas de problème, il me reste simplement à implémenter que l'utilisateur puisse ajouter ces mémos comme raccourcie sur le homescreen de son smartphone.
J'ai suivis de multiples exemple sur les forums mais rien de probant, le meilleur d'entre eux m'aillant simplement créé le raccourci mais pointant sur une application introuvable.
voici mon code actuel (celui-ci ne fais absolument rien ..) :
Listener bouton ajouter :
Fonction addShortcut() :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 } else if(actionId == ID_EPINGLER){ addShortcut(getApplicationContext()); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 void addShortcut(Context context){ Intent shortcutIntent = new Intent(); shortcutIntent.setClassName("ch.exemple.projet", "activité_a_lancer"); 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, "test"); //BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent()); //Bitmap newbit; newbit=bd.getBitmap(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.add); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(intent); }
Le manifest (ShowMemo = activité ou je crée le raccourci) :
Par la suite je devrais encore passer en paramètre un ID référancant le mémo éxacte à afficher dans l'activité d'affichage.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <activity android:name=".ShowMemo" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
Si quelqu'un à un exemple fonctionnel je suis preneur ! merci
Partager