2012-07-04 27 views
10

Facebook、Twitter、Google +などさまざまなソーシャルネットワークのソーシャル機能を統合する必要があるアプリケーションに取り組んでいます。他のアプリからFacebook、Twitter、Google Plusアプリのページを開きます - Android

今のところ、FacebookとTwitterでは、ユーザーがネイティブアプリケーションを持っていると認識されます。もしそうなら、私はそれを開いてファンページを表示します。 Twitterに

私は次のコードを使用します。

try { 

    Intent intent = new Intent(Intent.ACTION_VIEW, 
     Uri.parse("twitter://user?screen_name=[user_name]")); 
    startActivity(intent); 

    }catch (Exception e) { 
     startActivity(new Intent(Intent.ACTION_VIEW, 
      Uri.parse("https://twitter.com/#!/[user_name]"))); 
    } 

やFacebookのために次のコード:

try{ 

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + PROFILE_FACEBOOK_APP_ID)); 
startActivity(intent); 

}catch(Exception e){ 

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/UserNamePage"))); 
} 

今私がGoogle+のために同じことをやりたいと。次のURLのhttps://plus.google.com/MY_PAGE_ID/で私のファンページを閲覧することができましたが、Google +アプリケーションまたはブラウザで開くかどうかを尋ねてきます。質問をしなくても自動的にアプリケーションで開くことができますユーザー。

これを行う簡単な方法はありますか?おかげさまで

答えて

11

は解決策を見つけました、Google +アプリパッケージ名:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("https://plus.google.com/[Google+ID]/")); 
intent.setPackage("com.google.android.apps.plus"); // don't open the browser, make sure it opens in Google+ app 
startActivity(intent); 
+3

+1あなたのためにコードを共有する。 – VenomVendor

+0

ハードコードされたもの...パッケージ名などを変更するとどうなりますか? –

+0

@Ovidiu Latcuパッケージ名の場合、PackageManagerを使用して正しいパッケージ名を取得できます。 –

2

Googleプラスにインテントの他の情報が必要な場合は不明ですが、一般的なAndroidソリューションではターゲットを明示的に設定できます。 google +のパッケージ名が必要です。ここ

さらに詳しい情報:たとえばhttp://developer.android.com/reference/android/content/Intent.html#setPackage%28java.lang.String%29

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setClassName("com.google.android.apps.plus", 
"com.google.android.apps.plus.phone.UrlGatewayActivity"); 
intent.putExtra("customAppUri", "FAN_PAGE_ID"); 
startActivity(intent); 
+0

これは助けにはならないが、それでも同じ。ありがとう。 –

7

私たちはコンポーネントを指定する必要はありませんので、これは、非常に安全だと思う:

Intent.setPackage("com.google.android.apps.plus"); //Don't know the exact package name 
関連する問題