Pierre87 Posted September 3, 2010 Share Posted September 3, 2010 (edited) Salut! Pour une fois, je ne suis pas là pour poser une question, mais pour fournir des infos :D Dans mon appli, je veux afficher le profil Facebook de quelqu'un. Comme il n'y a aucune documentation, j'ai été obligé de décompiler l'apk :P (je n'ai bizarrement rien trouvé sur Google, suis-je le premier?) Voilà l'appel à faire : Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity"); intent.putExtra("extra_user_id", 123456789l); this.startActivity(intent); le extra_user_id DOIT être un long (bien faire attention) ne pas oublier non plus le try catch :D pour les curieux, il doit y avoir aussi d'autres paramètres : .field public static final EXTRA_LAUNCHED_INTERNALLY Ljava/lang/String; = "launched_internally" .field public static final EXTRA_USER_DISPLAY_NAME Ljava/lang/String; = "extra_user_display_name" .field public static final EXTRA_USER_FIRST_NAME Ljava/lang/String; = "extra_user_first_name" .field public static final EXTRA_USER_ID Ljava/lang/String; = "extra_user_id" .field public static final EXTRA_USER_LAST_NAME Ljava/lang/String; = "extra_user_last_name" .field public static final EXTRA_USER_TYPE Ljava/lang/String; = "extra_user_type" pour ceux qui sont ENCORE plus curieux, j'ai utilisé: http://dedexer.sourceforge.net/ Ca ne transforme pas en Java, mais c'est aisément compréhensible :) Edited September 3, 2010 by Pierre87 Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted September 3, 2010 Author Share Posted September 3, 2010 Comme je suis gentil, je vous poste mon boulot de la journée :) J'ai ajouté pas mal de chose : - Facebook : client officiel, web (touch) - Twitter : Twidroyd, Twidroyd Pro, client officiel, web Mon code va chercher la première solution disponible else if (v == this.facebook) { String facebookUid = this.json.optString("facebookUid", null); if (facebookUid != null) { try { long longFacebookUid = Long.parseLong(facebookUid); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity"); intent.putExtra("extra_user_id", longFacebookUid); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } try { String url = "http://touch.facebook.com/#/profile.php?id=" + facebookUid; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } } Toast.makeText(UserActivity.this, R.string.facebook_is_not_available, Toast.LENGTH_SHORT).show(); } else if (v == this.twitter) { String twitterUsername = this.json.optString("twitterUsername", null); if (twitterUsername != null) { try { String url = "http://twitter.com/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(); intent.setData(uri); intent.setClassName("com.twidroidpro", "com.twidroidpro.TwidroidProfile"); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } try { String url = "http://twitter.com/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(); intent.setData(uri); intent.setClassName("com.twidroid", "com.twidroid.TwidroidProfile"); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } String twitterUid = this.json.optString("twitterUid", null); if (twitterUid != null) { try { long longTwitterUid = Long.parseLong(twitterUid); try { Intent intent = new Intent(); intent.setClassName("com.twitter.android", "com.twitter.android.ProfileTabActivity"); intent.putExtra("user_id", longTwitterUid); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } } catch (NumberFormatException e) { e.printStackTrace(); } } try { String url = "http://mobile.twitter.com/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } } Toast.makeText(UserActivity.this, R.string.twitter_is_not_available, Toast.LENGTH_SHORT).show(); } C'est à adapter, mais ça marche :P J'utilise une source de donnée JSON, donc c'est normal que ça traine un peu partout dans le code :> Quote Link to comment Share on other sites More sharing options...
Fluckysan Posted September 3, 2010 Share Posted September 3, 2010 Merci Pierre87 ;) Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted September 3, 2010 Author Share Posted September 3, 2010 je bloque sur Tweetdeck là :x l'Activity reçoit un extra Serializable, mais je ne sais pas ce qu'il y a dedans :s Vous auriez un outil qui permet d'espionner les Intent du système? logcat ne fournit pas assez d'informations... Quote Link to comment Share on other sites More sharing options...
Fluckysan Posted September 7, 2010 Share Posted September 7, 2010 Je serais aussi intéressé Le système des Intent est bien fait mais il faut savoir quel Intent lancer ! Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted September 22, 2010 Author Share Posted September 22, 2010 Salut! Je viens de mettre à jour mon code : - Utilisation de "Intent.ACTION_VIEW" au lieu du nom direct de l'activity (quand c'est possible) - Support de TweetDeck Android (la solution était dans le manifest) - Suppression du support de l'application officielle Twitter (ils ont changé le nom de l'Activity, et ça provoque une SecurityException) private void openFacebookProfile() { String facebookUid = this.json.optString("facebookUid", null); if (facebookUid != null) { try { long longFacebookUid = Long.parseLong(facebookUid); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity"); intent.putExtra("extra_user_id", longFacebookUid); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } try { String url = "http://touch.facebook.com/#/profile.php?id=" + facebookUid; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } } Toast.makeText(UserActivity.this, R.string.facebook_is_not_available, Toast.LENGTH_SHORT).show(); } private void openTwitterProfile() { String twitterUsername = this.json.optString("twitterUsername", null); if (twitterUsername != null) { try { String url = "tweetdeck://at/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.addCategory(Intent.CATEGORY_DEFAULT); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } try { String url = "twitter://com.twidroidpro.twidroidprofile/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.addCategory(Intent.CATEGORY_DEFAULT); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } try { String url = "twitter://com.twidroid.twidroidprofile/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.addCategory(Intent.CATEGORY_DEFAULT); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } /* * String twitterUid = this.json.optString("twitterUid", null); * * if (twitterUid != null) { try { long longTwitterUid = * Long.parseLong(twitterUid); * * try { Intent intent = new Intent(); * intent.setClassName("com.twitter.android", * "com.twitter.android.ProfileActivity"); * intent.putExtra("user_id", longTwitterUid); * * this.startActivity(intent); * * return; } catch (ActivityNotFoundException e) { * e.printStackTrace(); } } catch (NumberFormatException e) { * e.printStackTrace(); } } */ try { String url = "http://mobile.twitter.com/" + twitterUsername; Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); this.startActivity(intent); return; } catch (ActivityNotFoundException e) { e.printStackTrace(); } } Toast.makeText(UserActivity.this, R.string.twitter_is_not_available, Toast.LENGTH_SHORT).show(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.