简体   繁体   English

Android Intent将在Google+社区屏幕上发布Google+应用

[英]Android Intent to launch Google+ app at Google+ Community screen

There is already a good SO question for displaying a Google+ Page in the Google+ Android app: 在Google+ Android应用中显示Google+信息页已经有了一个很好的问题:

Open Google Plus Page Via Intent In Android 通过Intent在Android中打开Goog​​le Plus页面

But what about the Intent to launch the Google+ app at a specific Google+ Community? 但是,如果想要在特定的Google+社区推出Google+应用,那该怎么办?

EDIT - to the silent down-voters, please explain why you down-voted. 编辑 - 对于沉默的选民,请解释为什么你投票。

My solution, working with G+ version "5.3.0.91034052", tested today 我的解决方案,使用G +版本“5.3.0.91034052”,今天进行了测试

final Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "https://plus.google.com/communities/107847486351510098159" ) );
intent.setPackage( "com.google.android.apps.plus" );
if (intent.resolveActivity(getPackageManager()) != null) { 
    startActivity( intent );
}

It's not bullet proof, you need Google+ app on your device, in case you don't have it some kind of try-catch might be nice (?), 这不是防弹,你需要在你的设备上使用Google+应用程序,如果你没有它,某种尝试捕获可能会很好(?),

I achieved this by using: 我通过使用:

String communityPage = "communities/123456789";
    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", communityPage);
        startActivity(intent);
        } catch(ActivityNotFoundException e) {
            // fallback if G+ app is not installed
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+communityPage)));
        }

Where 123456789 is the id of the community copied from the address bar. 其中123456789是从地址栏复制的社区的ID。

Just in case anyone else needs to do this I had to do this in my app and used the below code 为了防止其他人需要这样做,我必须在我的应用程序中执行此操作并使用以下代码

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

Where 1234356789 is the community id from the address bar. 其中1234356789是地址栏中的社区ID。

This then prompts whether you want to open with Google+ or browser. 然后会提示您是否要使用Google+或浏览器打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM