温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android中怎么接入Google+分享功能

发布时间:2021-07-12 13:57:59 来源:亿速云 阅读:171 作者:Leah 栏目:移动开发

这篇文章给大家介绍Android中怎么接入Google+分享功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

Android使用Google+分享功能

1.首先将<android-sdk-folder>/extras/google/google_play_services 导入到Eclipse中

我将google-play-services_lib复制到了新建的thirdlib文件中然后导入的,大家可以直接导入。

如果没有这个工程首先更新到最新的ADT,然后打开Android SDK Manager进行下载

2.然后将其作为 google-play-services_lib作为lib工程add到我们的工程上

Android中怎么接入Google+分享功能

3.主要的分享代码:

	//google+分享
	public void doGooglePlusShare(Activity mContext) {
		
		// 判断是否安装Google Service
		
		if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext) == ConnectionResult.SUCCESS) {

		
				Intent shareIntent = new PlusShare.Builder(mContext).setType("text/plain")
						.setText("test share").setContentUrl(Uri.parse("www.baidu.com")).getIntent();

			    mContext.startActivityForResult(shareIntent,
						0);
		
		
		}else{
			
			Toast.makeText(mContext, "Please install Google Service", 0).show();
			
		}
		
	}

在Button的点击时间种调用这个方法

4.配置AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googleplusshare"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.googleplusshare.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
           <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
    
    <uses-permission android:name="android.permission.INTERNET"/>

</manifest>

关于Android中怎么接入Google+分享功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI