溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2021-07-12 13:57:59 來(lái)源:億速云 閱讀:184 作者:Leah 欄目:移動(dòng)開(kāi)發(fā)

這篇文章給大家介紹Android中怎么接入Google+分享功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

Android使用Google+分享功能

1.首先將<android-sdk-folder>/extras/google/google_play_services 導(dǎo)入到Eclipse中

我將google-play-services_lib復(fù)制到了新建的thirdlib文件中然后導(dǎo)入的,大家可以直接導(dǎo)入。

如果沒(méi)有這個(gè)工程首先更新到最新的ADT,然后打開(kāi)Android SDK Manager進(jìn)行下載

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的點(diǎn)擊時(shí)間種調(diào)用這個(gè)方法

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>

關(guān)于Android中怎么接入Google+分享功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI