2012-08-08 5 views
21

Ich habe eine Google Plus SeiteÖffnen Sie Google Plus Seite Via Intent In Android

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

und eine Android-Anwendung. Ich möchte diese Seite in meiner App öffnen. Ich möchte den Browser nicht öffnen!

Dies öffnet den Browser:

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

diese Abstürze:

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

Vielen Dank im Voraus!

[gelöst]

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

Mit dieser Lösung der Benutzer des Google Plus APP können wählen, oder den Browser öffnen. Wenn die APP ausgewählt ist, gibt es keinen Absturz.

+0

) Wie sieht es mit dem Einbetten eines WebView in Ihre App und dem Laden der Seite aus? ? – Nick

+0

dafür bevorzuge ich den Browser direkt öffnen. – benoffi7

+0

Wie wäre es für eine Google+ Community? Http://stackoverflow.com/questions/23075842/android-intent-to-launch-google-app-at-google-community-screen –

Antwort

24

Wenn der Benutzer die Google+ App installiert ist, können Sie dies tun:

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

Beachten Sie die Syntax der URI, und dass es nicht /b/id/ enthält.

1

Was sagt die Stapelspur, wenn sie abstürzt?

Auch ich bin mir nicht sicher, ob dies einen Unterschied machen würde, aber es gibt einen Tippfehler in der ID. Sie schrieb:

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

aber ursprünglich die ID war 101839105638971401281. Du hast die 1 am Ende verlassen.

21

Sie müssen zuerst überprüfen, ob der Benutzer bereits G + App in seinem Telefon hat oder nicht? Wenn ja, dann können wir es mit einer bestimmten Absicht starten oder wir können die Browserumleitung auf eine bestimmte Seite anwenden.

Hier ist eine Methode in einer solchen Strömung,

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

Jetzt können Sie diese Methode aufrufen kann einfach wie,

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

Erweiterte Antwort: gleiche Art und Weise für twitter und facebook Sie verwenden können ,

Für 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))); 
     } 
} 

Und für 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

Ändern Sie die Gateway-Aktivität zu: com.google.android.libraries.social.gateway.GatewayActivity – Amt87

+0

Über "com.google.android.apps.plus. phone.UrlGatewayActivity ", sollten Sie niemals davon ausgehen, dass dies der Pfad zu der Aktivität ist. Verwenden Sie stattdessen nur den Paketnamen, indem Sie queryIntentActivities aufrufen, a Und dann überprüfe, welcher von ihnen mit dem Paketnamen der App übereinstimmt. –

+0

Für fb: Die URL für die Web-Absicht sollte geändert werden, um nur "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

Warum nicht einfach Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); . Android OS fragt alle Anwendungen ab, die mit einem bestimmten Uri umgehen können.Google+ ist als App so programmiert, dass es mit dem von Ihnen angeforderten Uri umgehen kann. Es wird also als Option in einem Chooser angezeigt (oder wenn der Nutzer die Google+ App bereits als Standard für diesen Uri ausgewählt hat.

Verwandte Themen