2012-08-08 18 views
21

Ho un Google Plus paginaApri Google Plus Pagina Via intenti Android

https://plus.google.com/u/0/b/101839105638971401281/101839105638971401281/posts

e un'applicazione Android. Voglio aprire questa pagina nella mia app. Non voglio aprire il browser!

Questo apre il browser:

URL="https://plus.google.com/b/101839105638971401281/101839105638971401281/posts"; 
uri = Uri.parse(URL); 
it = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(it); 

questa si blocca:

Intent intent = new Intent(Intent.ACTION_VIEW); 

intent.setClassName("com.google.android.apps.plus",    "com.google.android.apps.plus.phone.UrlGatewayActivity"); 

intent.putExtra("customAppUri", "10183910563897140128"); 
startActivity(intent); 

Grazie in anticipo!

[risolto]

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/101839105638971401281/posts"))); 

Con questa soluzione l'utente può scegliere la Google Plus APP o aprire il browser. Se viene scelta l'APP, non si verifica un arresto anomalo.

+0

Che ne dici di incorporare una WebView nella tua app e di caricare la pagina lì ? – Nick

+0

per questo preferisco aprire direttamente il browser. – benoffi7

+0

Che ne dici di una Community Google+? Http://stackoverflow.com/questions/23075842/android-intent-to-launch-google-app-at-google-community-screen –

risposta

24

Se l'utente ha installato l'app Google+, si può fare questo:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/101839105638971401281/posts"))); 

Avviso la sintassi del URI, e che non contiene /b/id/.

1

Cosa dice la traccia dello stack quando si blocca?

Anche io non sono sicuro se questo farebbe la differenza ma c'è un refuso nell'ID. Hai scritto:

intent.putExtra("customAppUri", "10183910563897140128"); 

ma originariamente l'ID era 101839105638971401281. Hai lasciato il 1 alla fine.

21

Devi prima controllare che l'utente abbia già l'app G + nel suo telefono o no? Se sì, possiamo avviarlo con un intento specifico oppure possiamo utilizzare il reindirizzamento del browser a una pagina specifica.

Ecco un metodo di tale flusso,

public void openGPlus(String profile) { 
    try { 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setClassName("com.google.android.apps.plus", 
      "com.google.android.apps.plus.phone.UrlGatewayActivity"); 
     intent.putExtra("customAppUri", profile); 
     startActivity(intent); 
    } catch(ActivityNotFoundException e) { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+profile+"/posts"))); 
    } 
} 

Ora è possibile chiamare questo metodo semplicemente come,

//117004778634926368759 is my google plus id 
openGPlus("117004778634926368759"); 

Risposta estesa: stesso modo per twitter e facebook è possibile utilizzare ,

Per Twitter,

public void openTwtr(String twtrName) { 
     try { 
      startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://user?screen_name=" + twtrName))); 
     } catch (ActivityNotFoundException e) { 
      startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/#!/" + twtrName))); 
     } 
} 

E per Facebook,

public void openFB(String facebookId) { 
    try{ 
     String facebookScheme = "fb://profile/" + facebookId; 
     Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme)); 
     startActivity(facebookIntent); 
    } catch (ActivityNotFoundException e) { 
     Intent facebookIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/profile.php?id="+facebookId)); 
     startActivity(facebookIntent); 
    } 
} 
+2

Modificare l'attività del gateway su: com.google.android.libraries.social.gateway.GatewayActivity – Amt87

+0

Informazioni su "com.google.android.apps.plus. phone.UrlGatewayActivity ", non dovresti mai presumere che questo sia il percorso dell'attività, ma usa solo il packageName, chiamando queryIntentActivities, a e poi controlla quale di essi corrisponde al packageName dell'app. –

+0

Per fb: l'url per l'intento del web deve essere modificato in "https://www.facebook.com/"+facebookId –

3
/** 
* Intent to open the official Google+ app to the user's profile. If the Google+ app is not 
* installed then the Web Browser will be used. 
* 
* </br></br>Example usage:</br> 
* <code>newGooglePlusIntent(context.getPackageManager(), "https://plus.google.com/+JaredRummler");</code> 
* 
* @param pm 
*   The {@link PackageManager}. 
* @param url 
*   The URL to the user's Google+ profile. 
* @return The intent to open the Google+ app to the user's profile. 
*/ 
public static Intent newGooglePlusIntent(PackageManager pm, String url) { 
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
    try { 
     if (pm.getPackageInfo("com.google.android.apps.plus", 0) != null) { 
      intent.setPackage("com.google.android.apps.plus"); 
     } 
    } catch (NameNotFoundException e) { 
    } 
    return intent; 
} 
0

Perché non solo Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); . Android OS interroga tutte le applicazioni in grado di gestire un Uri specifico.Google+, come app, è programmato per essere in grado di gestire l'Uri che stai richiedendo. Quindi verrà visualizzato come opzione in un selettore (o verrà visualizzato solo se l'utente ha già selezionato l'app Google+ come predefinita per Uri.

Problemi correlati