2012-08-08 17 views
21

Tengo una página Google PlusAbre Google Plus página a través de Intención En Android

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

y una aplicación para Android. Quiero abrir esta página en mi aplicación. ¡No quiero abrir el navegador!

Esto abre el navegador:

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

choques esto:

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); 

Gracias de antemano!

[SOLUCIONADO]

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

Con esta solución, el usuario puede elegir el Google Plus APP o abrir el navegador. Si se elige la aplicación, no se produce un bloqueo.

+0

¿Qué hay de incluir un WebView en su aplicación y cargar la página allí? ? – Nick

+0

para eso prefiero abrir el navegador directamente. – benoffi7

+0

¿Qué tal para una comunidad de Google+? Http://stackoverflow.com/questions/23075842/android-intent-to-launch-google-app-at-google-community-screen –

Respuesta

24

Si el usuario tiene instalada la aplicación de Google+, puede hacer esto:

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

Aviso la sintaxis del URI, y que no contiene /b/id/.

1

¿Qué dice el seguimiento de pila cuando se bloquea?

Además, no estoy seguro de si esto marcaría la diferencia, pero hay un error ortográfico en la identificación. Usted escribió:

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

pero originalmente la identificación fue 101839105638971401281. Dejaste el 1 al final.

21

Primero debes comprobar que el usuario ya tiene la aplicación G + en su teléfono o no? En caso afirmativo, podemos iniciarlo con una intención específica o podemos usar la redirección del navegador a una página específica.

Aquí es un método en dicho flujo,

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"))); 
    } 
} 

Ahora se puede llamar a este método simplemente como,

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

respuesta ampliada: mismo camino para twitter y facebook se puede utilizar ,

Para 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))); 
     } 
} 

Y para 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

Cambie la actividad de la puerta de enlace a: com.google.android.libraries.social.gateway.GatewayActivity – Amt87

+0

Acerca de "com.google.android.apps.plus. phone.UrlGatewayActivity ", nunca debe suponer que esta es la ruta de acceso a la actividad. En su lugar, use solo packageName, llamando a queryIntentActivities, a y luego verifique cuál de ellos coincide con el nombre del paquete de la aplicación. –

+0

Para fb: la url para la intención web debe cambiarse a solo "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

¿Por qué no Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); . El sistema operativo Android consulta todas las aplicaciones que pueden manejar un Uri específico.Google+, como aplicación, está programado para poder manejar el URI que está solicitando. Por lo tanto, se mostrará como una opción en un selector (o simplemente acceda si el usuario ya ha seleccionado la aplicación de Google+ para ser el valor predeterminado para ese Uri.

Cuestiones relacionadas