Art*_*nce 7 android android-intent google-plus
我的要求是在社交网站上分享.所以,我已经完成了Facebook和Twitter.但我被困在了Google+
.我有以下代码要分享Google+
,但forcecloses
我开始活动时的应用程序.仅当Google+ app
尚未在设备上安装时才会发生这种情况.我知道此共享意图要求已安装Google+才能启动此活动.
现在我需要做的是至少告知用户google+
共享需要已经google+ app
通过对话框或吐司安装而不是强制关闭(如果可能的话,点击对话框上的确定应该重定向到Google Play上的google +).如果谷歌+应用程序已安装,它会像往常一样.
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Hello there! This is a pic of the lazy cat")
.setType("image/jpeg")
.setStream(Uri.parse(path))
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.提前致谢.
更新 以下答案已过时.您现在可以通过Google Play服务库检查Google+应用是否已安装(可通过Android SDK获得).有关如何将其添加到项目中的信息,请参见此处.
例:
int errorCode = GooglePlusUtil.checkGooglePlusApp(mContext);
if (errorCode != GooglePlusUtil.SUCCESS) {
//Google+ is either not present or another error occured, show the error dialog
GooglePlusUtil.getErrorDialog(errorCode, this, 0).show();
}
else{
//Your Google+ related code here
}
Run Code Online (Sandbox Code Playgroud)
老答复
您可以创建某种检查以查看是否已安装Google+应用:
public void loadGooglePlus()
{
if(isGooglePlusInstalled())
{
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Hello there! This is a pic of the lazy cat")
.setType("image/jpeg")
.setStream(Uri.parse(path))
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
}
else{
//Notify user
}
}
public boolean isGooglePlusInstalled()
{
try
{
getPackageManager().getApplicationInfo("com.google.android.apps.plus", 0 );
return true;
}
catch(PackageManager.NameNotFoundException e)
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1937 次 |
最近记录: |