天天看點

極光分享內建

主要場景:

  • 将分享内容分享到 QQ、微信、新浪微網誌、Facebook、Twitter 等主要的社交平台。
  • 獲得 QQ、微信、新浪微網誌、Facebook、Twitter 等主要平台授權。
  • 擷取 QQ、微信、新浪微網誌、Facebook、Twitter 等主要平台的個人資訊,用于第三方登入。

內建步驟

  • 在 gradle 配置 jcenter。
  • manifest.xml配置
  • 配置第三方平台資訊。
  • 配置微信回調(如不需要分享到微信,可跳過)。
  • 配置項目簽名。
  • 參考 example 工程或者接口文檔使用 JShare SDK。

Gradle配置

  • Project 根目錄的主 gradle 中配置了 jcenter 支援。
buildscript {
    repositories {
        jcenter()
    }
    ......
}

allprojects {
    repositories {
        jcenter()
    }
}
           
  • 在 module 的 gradle 中添加依賴和 AndroidManifest 的替換變量。
android {
    ......
    defaultConfig {
        applicationId "com.xxx.xxx" //極光控制台建立應用時填寫的應用包名.
        ......

        ndk {
            //選擇要添加的對應 cpu 類型的.so 庫。
            abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a'
            // 還可以添加 'x86', 'x86_64', 'mips', 'mips64'
        }

        manifestPlaceholders = [
            JSHARE_PKGNAME : applicationId,
            JPUSH_APPKEY : "你的 appkey", //極光控制台建立應用得到的 AppKey.
            JPUSH_CHANNEL : "developer-default", //暫時填寫預設值即可.
            TENCENT_APPID: " QQ 開發者應用的 appID ",//騰訊開放平台注冊應用得到的 appId
            FACEBOOK_APPID: " facebook 開發者應用的 appID ",// facebook 注冊應用得到的 appId
        ]
        ......
    }
    ......
}

dependencies {
    ......
    compile 'cn.jiguang.sdk:jshare:1.5.0'  // 此處以 JShare 1.5.0 版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jshare-qqmodel:1.5.0'  // 此處以 jshare-qqmodel 1.5.0  版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jshare-wechatmodel:1.5.0'  // 此處以 jshare-wechatmodel 1.5.0  版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jshare-sinamodel:1.5.0'  // 此處以 jshare-sinamodel 1.5.0  版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jshare-facebookmodel:1.5.0'  // 此處以 jshare-facebookmodel 1.5.0  版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jshare-twittermodel:1.5.0'  // 此處以 jshare-twittermodel 1.5.0  版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    compile 'cn.jiguang.sdk:jcore:1.1.7'  // 此處以 JCore 1.1.7 版本為例,具體版本請參考壓縮包 libs 的 jar 包版本。
    ......
}
           

manifest.xml

  • 權限配置
<!-- Required -->
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <!-- Optional. Required for location feature -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
           
  • SDK 核心功能(分享回調可以不寫)
<!-- Required SDK 核心功能-->
 <activity
      android:name="cn.jiguang.share.android.ui.JiguangShellActivity"
      android:configChanges="keyboardHidden|orientation|screenSize"
      android:exported="true"
      android:launchMode="singleTask"
      android:screenOrientation="portrait"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      android:windowSoftInputMode="stateHidden|adjustResize">
      <!-- Optional QQ 分享回調-->
      <!-- scheme為“tencent” 字首再加上 QQ 開發者應用的 appID;例如 appID為123456,則 scheme=“tencent123456” -->
      <intent-filter>
          <data android:scheme="tencent+appID" />
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.BROWSABLE" />
          <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>

      <!-- Optional 新浪微網誌分享回調 -->
      <intent-filter>
          <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
          <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>

      <!-- Optional 新浪微網誌私信回調 -->
      <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="jsharesdk" android:host="sinaweibo"/>
      </intent-filter>
</activity>
           

配置第三方平台資訊

JGShareSDK.xml 示例

<?xml version="1.0" encoding="utf-8"?>
<DevInfor>

    <!-- 如果不需要支援某平台,可預設該平台的配置-->

    <SinaWeibo
        AppKey="新浪微網誌的 AppKey"
        AppSecret="新浪微網誌 AppSecret"
        RedirectUrl="微網誌開放平台填寫的授權回調頁"/>

    <QQ
        AppId="QQ 的 AppId"
        AppKey="QQ 的 AppKey"/>

    <Wechat
        AppId="微信的 AppId"
        AppSecret="微信的 AppSectet"/>

    <Facebook
        AppId="facebook 的 appId"
        AppName="facebook 背景填寫的名稱"
    />

    <Twitter
        ConsumerKey="twitter 的 ConsumerKey"
        ConsumerSecret="twitter 的 ConsumerSecret"
    />

</DevInfor>
           

配置簽名

在項目的 build.gradle 的 android 内部新增簽名配置,例如:

signingConfigs {
        debug {
              storeFile file("jshare.jks") //簽名檔案路徑
              storePassword "sdkteam"
              keyAlias "jshare"
              keyPassword "sdkteam" //簽名密碼
        }
        release {
             storeFile file("jshare.jks") //簽名檔案路徑
             storePassword "sdkteam"
             keyAlias "jshare"
             keyPassword "sdkteam" //簽名密碼
        }
    }
           

然後在項目的 build.gradle 的 buildTypes 使用簽名配置,例如:

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }
           

Application中初始化

public static void setDebugMode(boolean enable)
public static void init(Context context)
           

極光分享

繼續閱讀