Android借用QQ開放平台,簡單實現聯絡客服功能

來源:互聯網
上載者:User

標籤:開放平台   應用   app   聊天   android   

公司做的電商APP,現在要加入聯絡客服功能,起初想的是做一個即時聊天系統,以前沒做過,這兩天開始惡補,後來需求變了,改成調用QQ開放平台,做一個臨時會話就行了,這就省了不少力氣,也不需要再去元件服務端了。

步驟:

1.引用QQ SDK源碼檔案。

建立一個工程,並把open-sdk.jar檔案和mta_sdk_x.x.x.jar檔案拷貝到libs(或lib)目錄下,如所示:

選中open-sdk.jar和mta_sdk_x.x.x.ja,右鍵菜單中選擇Build Path, 選擇Add to Build Path


2.給應用的AndroidManifest增加SDK需要的配置;

在應用的AndroidManifest.xml增加配置的<application>節點下增加以下配置(註:不配置將會導致無法調用API)

<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><application><activity android:name="com.tencent.connect.common.AssistActivity"            android:theme="@android:style/Theme.Translucent.NoTitleBar"             android:screenOrientation="portrait"/><activity        android:name="com.tencent.tauth.AuthActivity"        android:noHistory="true"        android:launchMode="singleTask" >    <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="tencent你的AppId" />     </intent-filter></activity><application>

其中,如果你已經添加了"android.permission.INTERNET"和"android.permission.ACCESS_NETWORK_STATE"許可權,則無需重複添加。

 而"你的AppId"則要替換成具體應用的AppId,例如你的AppId是"222222",則<data>標籤應該是這樣的:

<data android:scheme="tencent222222" />

3.編寫Android代碼

String text = (String) tittle.getText();QQAuth mqqAuth = QQAuth.createInstance("10000000", mContext); // 10000000為你申請的APP_ID,mContext是上下文WPA mWPA = new WPA(this, mqqAuth.getQQToken());String ESQ = "512821255";  //512821255為客服QQ號int ret = mWPA.startWPAConversation(ESQ, "你好,我正在樂寵看這個商品~\n"+text); //客服QQif (ret != 0) { //如果ret不為0,就說明調用SDK出現了錯誤Toast.makeText(getApplicationContext(),"抱歉,聯絡客服出現了錯誤~. error:" + ret,Toast.LENGTH_LONG).show();}

text中的內容我取得是商品詳情頁中的標題文字,做聯絡客服的開場提示



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.