国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

瀏覽:143日期:2022-06-04 16:05:38

個(gè)人感覺mob平臺(tái)功能還是比較強(qiáng)大的,很多功能都可以通過他們平臺(tái)來實(shí)現(xiàn)。

建議仔細(xì)觀看每一個(gè)步驟,如果一個(gè)步驟沒處理好,可能就會(huì)讓你的這個(gè)功能無法實(shí)現(xiàn)。相信我一定可以成功的。廢話少說,先看一下效果:

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

1.在mob平臺(tái)配置ShareSDK環(huán)境1.如何在mob平臺(tái)創(chuàng)建應(yīng)用

下面為我創(chuàng)建的應(yīng)用,如圖所示,我們選擇接入的接口為ShareSDK

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

2.獲取你的App Key和App Secret(建議用自己的)

獲取你先創(chuàng)建應(yīng)用的App Key和App Secret,這里主要告訴你在哪里找App Key和App Secret,因?yàn)榈认滦枰玫健?/p>

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

3.點(diǎn)擊SDK下載

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

4.選擇ShareSDK

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

選擇配置我們主要選擇下方配置,然后點(diǎn)擊保存配置(下面我會(huì)說明為什么只選擇這些配置)

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

5.點(diǎn)擊下載,就會(huì)彈出下載提示

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

6.關(guān)于為什么只選擇這些配置?

可以從上圖中看出,無論是QQ還微博,微信等都需要獲取他們平臺(tái)的appId和appKey。如果你直接使用平臺(tái)的提供的appId和appKey是不能成功的。如果我想要實(shí)現(xiàn)這些功能,我們得先去那些平臺(tái)獲取他的appId和appKey。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

7.我創(chuàng)建的QQ開發(fā)者平臺(tái)應(yīng)用

下面是我創(chuàng)建成功的應(yīng)用,說實(shí)話QQ的這個(gè)服務(wù)確實(shí)挺慢的,一般審核需要幾天,可以是免費(fèi)的原因吧。下面是創(chuàng)建應(yīng)用的步驟。1.成為個(gè)人開發(fā)者。2.創(chuàng)建移動(dòng)應(yīng)用。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

2.把ShareSDK部署到android1.新建一個(gè)moudle或者project

這個(gè)就不細(xì)說,比較簡(jiǎn)單。

2.配置你的build.gradle(Project)文件

如圖所示,添加如圖代碼:

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

代碼如下:

classpath 'com.mob.sdk:MobSDK:2018.0319.1724'3.配置你的build.gradle(Module)文件

1.首先加入如圖代碼

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

根據(jù)你的情況選擇:代碼如下,因?yàn)槲业陌姹臼莂ndroid studio 4.2最新版,加入方法如下:

id ’com.mob.sdk’

如果是其他android studio 3點(diǎn)多的版本,添加方法代碼:

apply plugin:’com.mob.sdk’

2.其次加入下圖代碼

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

加入代碼如下(建議使用自己申請(qǐng)的appId和appKey,如果你使用的是我QQ申請(qǐng)的appId和appKey話,你是成功不了,關(guān)于為什么成功不了,我下面將會(huì)說明):

MobSDK {fp true //嚴(yán)格模式 } MobSDK {appKey '31c48ca47c70e'appSecret '2d7adbfcd73363bbbe41aeff60e41e4f'ShareSDK { loopShare true devInfo {SinaWeibo { appKey '568898243' appSecret '38a4f8204cc784f81f9f0daaf31e02e3' callbackUri 'http://www.sharesdk.cn'}QQ { appId '101906011' appKey '676d885e518445fed4d7d2341ff2d56f'}TencentWeibo { appKey '801307650' appSecret 'ae36f4ee3946e1cbb98d6965b0b2ff5c' callbackUri 'http://www.sharesdk.cn'}QZone { appId '100371282' appKey 'aed9b0303e3ed1e27bae87c33761161d'} }} }

3. 解釋一下關(guān)于為什么成功不了

下面我創(chuàng)建的應(yīng)用

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

我們可以看一下在QQ平臺(tái)創(chuàng)建的應(yīng)用包名和應(yīng)用簽名如下

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

然后我們?cè)诎阉臀覄?chuàng)建的android項(xiàng)目來對(duì)比一下:1.我的包名和他相同

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

2.我們可以看一下我們的MD5是否相同第一步:如果查看你的項(xiàng)目的MD5找到圖中的gradle

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

點(diǎn)擊圖中紅色圓圈處

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

然后就可以查看MD5了

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

第二步:將我的MD5的去掉’:號(hào)’,把大寫改為小寫,我們對(duì)比一下是相同的。

補(bǔ)充條件小彩蛋:如果你新建其他項(xiàng)目android項(xiàng)目的時(shí)候需要用到QQ的appId和appKey的話,你可以直接點(diǎn)擊下圖中的修改,修改你為你新項(xiàng)目的包名和MD5。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

即可直接進(jìn)行修改

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

4.配置你的AndroidManifest.xml文件

加入如圖回調(diào)和權(quán)限。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

代碼如下:

權(quán)限:

<uses-permission android:name='android.permission.GET_TASKS' /> <uses-permission android:name='android.permission.INTERNET' /> <uses-permission android:name='android.permission.ACCESS_WIFI_STATE' /> <uses-permission android:name='android.permission.ACCESS_NETWORK_STATE' /> <uses-permission android:name='android.permission.CHANGE_WIFI_STATE' /> <uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' /> <uses-permission android:name='android.permission.READ_PHONE_STATE' /> <uses-permission android:name='android.permission.MANAGE_ACCOUNTS'/> <uses-permission android:name='android.permission.GET_ACCOUNTS'/> <!-- 藍(lán)牙分享所需的權(quán)限 --> <uses-permission android:name='android.permission.BLUETOOTH' /> <uses-permission android:name='android.permission.BLUETOOTH_ADMIN' />

回調(diào)代碼:

<activity android:name='com.mob.tools.MobUIShell' android:theme='@android:style/Theme.Translucent.NoTitleBar' android:configChanges='keyboardHidden|orientation|screenSize' android:screenOrientation='portrait' android:windowSoftInputMode='stateHidden|adjustResize' tools:ignore='LockedOrientationActivity'> <!-- QQ和QQ空間分享 QQ登錄的回調(diào)必須要配置的 --> <intent-filter> <data android:scheme='tencent101906011' /> <action android:name='android.intent.action.VIEW' /> <category android:name='android.intent.category.BROWSABLE' /> <category android:name='android.intent.category.DEFAULT' /> </intent-filter> <!-- 新浪微博客戶端分享回調(diào)必須配置 --> <intent-filter> <action android:name='com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY' /> <category android:name='android.intent.category.DEFAULT' /> </intent-filter> </activity>

注意事項(xiàng):記得把如圖紅色圓圈處的101906011改為你的QQ平臺(tái)創(chuàng)建的應(yīng)用申請(qǐng)的appId。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

5.配置activity.xml文件。

比較簡(jiǎn)單,主要添加幾個(gè)控件用來接收數(shù)據(jù)

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

代碼如下

<?xml version='1.0' encoding='utf-8'?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <TextViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_marginTop='24dp'android:text='名字'android:textSize='20sp'app:layout_constraintEnd_toEndOf='@+id/imageView'app:layout_constraintStart_toStartOf='@+id/imageView'app:layout_constraintTop_toBottomOf='@+id/imageView'></TextView> <Buttonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_marginTop='340dp'android:text='QQ登錄'app:layout_constraintEnd_toEndOf='parent'app:layout_constraintHorizontal_bias='0.476'app:layout_constraintStart_toStartOf='parent'app:layout_constraintTop_toTopOf='parent' /> <ImageViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_marginTop='56dp'android:src='http://www.intensediesel.com/bcjs/@mipmap/ic_launcher_round'app:layout_constraintEnd_toEndOf='parent'app:layout_constraintStart_toStartOf='parent'app:layout_constraintTop_toTopOf='parent' /> <TextViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_marginTop='24dp'android:text='性別'app:layout_constraintEnd_toEndOf='@+id/text'app:layout_constraintStart_toStartOf='@+id/text'app:layout_constraintTop_toBottomOf='@+id/text' /> <Buttonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_marginTop='50dp'android:text='QQ分享'app:layout_constraintEnd_toEndOf='parent'app:layout_constraintStart_toStartOf='parent'app:layout_constraintTop_toBottomOf='@+id/button' /></androidx.constraintlayout.widget.ConstraintLayout>6.配置Activity.java文件1.記得把MobSDK.init里面的AppKey和AppSecret改為你自己申請(qǐng)你的。2.qq登錄代碼

Platform qq = ShareSDK.getPlatform(QQ.NAME);qq.SSOSetting(false); // 設(shè)置false表示使用SSO授權(quán)方式qq.authorize();thirdLoginId = qq.getDb().getUserId();name = qq.getDb().getUserName();image = qq.getDb().getUserIcon();sex = qq.getDb().getUserGender();Toast.makeText(MainActivity.this,'name='+image,Toast.LENGTH_LONG).show();TextView textView=findViewById(R.id.text);textView.setText(name);Log.e('Toast','image='+thirdLoginId);ImageView imageView=findViewById(R.id.imageView);Glide.with(MainActivity.this) .load(image) .into(imageView);TextView textView1=findViewById(R.id.textView);if(sex!=null){ if(sex=='m'){ sex= '男'; }else { sex='女'; }}textView1.setText(sex);

記得導(dǎo)入Glide依賴,因?yàn)楂@取的圖片地址為網(wǎng)絡(luò)圖片地址

implementation ’com.github.bumptech.glide:glide:4.11.0’3.qq分享代碼

OnekeyShare oks = new OnekeyShare();// title標(biāo)題,微信、QQ和QQ空間等平臺(tái)使用 oks.setTitle('分享');// titleUrl QQ和QQ空間跳轉(zhuǎn)鏈接 oks.setTitleUrl('http://sharesdk.cn');// text是分享文本,所有平臺(tái)都需要這個(gè)字段 oks.setText('我是分享文本');// setImageUrl是網(wǎng)絡(luò)圖片的url oks.setImageUrl('https://hmls.hfbank.com.cn/hfapp-api/9.png');// url在微信、Facebook等平臺(tái)中使用 oks.setUrl('http://sharesdk.cn');// 啟動(dòng)分享GUI oks.show(MobSDK.getContext());4.總體代碼

package com.example.mobsharetest;import androidx.appcompat.app.AppCompatActivity;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.mob.MobSDK;import org.w3c.dom.Text;import java.util.HashMap;import cn.sharesdk.framework.Platform;import cn.sharesdk.framework.PlatformActionListener;import cn.sharesdk.framework.ShareSDK;import cn.sharesdk.onekeyshare.OnekeyShare;import cn.sharesdk.sina.weibo.SinaWeibo;import cn.sharesdk.tencent.qq.QQ;public class MainActivity extends AppCompatActivity { private Button button; private Button button2; String thirdLoginId; String name; String image; String sex; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);MobSDK.init(this, '31c48ca47c70e','2d7adbfcd73363bbbe41aeff60e41e4f');MobSDK.submitPolicyGrantResult(true, null);button=findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {Platform qq = ShareSDK.getPlatform(QQ.NAME);qq.SSOSetting(false); // 設(shè)置false表示使用SSO授權(quán)方式qq.authorize();thirdLoginId = qq.getDb().getUserId();name = qq.getDb().getUserName();image = qq.getDb().getUserIcon();sex = qq.getDb().getUserGender();Toast.makeText(MainActivity.this,'name='+image,Toast.LENGTH_LONG).show();TextView textView=findViewById(R.id.text);textView.setText(name);Log.e('Toast','image='+thirdLoginId);ImageView imageView=findViewById(R.id.imageView);Glide.with(MainActivity.this).load(image).into(imageView);TextView textView1=findViewById(R.id.textView);if(sex!=null){ if(sex=='m'){sex= '男'; }else {sex='女'; }}textView1.setText(sex); }});button2=findViewById(R.id.button2);button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {OnekeyShare oks = new OnekeyShare();// title標(biāo)題,微信、QQ和QQ空間等平臺(tái)使用oks.setTitle('分享');// titleUrl QQ和QQ空間跳轉(zhuǎn)鏈接oks.setTitleUrl('http://sharesdk.cn');// text是分享文本,所有平臺(tái)都需要這個(gè)字段oks.setText('我是分享文本');// setImageUrl是網(wǎng)絡(luò)圖片的urloks.setImageUrl('https://hmls.hfbank.com.cn/hfapp-api/9.png');// url在微信、Facebook等平臺(tái)中使用oks.setUrl('http://sharesdk.cn');// 啟動(dòng)分享GUIoks.show(MobSDK.getContext()); }}); }}

步驟有點(diǎn)復(fù)雜,因?yàn)檫@個(gè)功能確實(shí)比較難以實(shí)現(xiàn),如果有什么問題的話,可以提出來,一不小心就寫14000多個(gè)字了。

詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享

以上就是詳解android在mob平臺(tái)實(shí)現(xiàn)qq登陸和分享的詳細(xì)內(nèi)容,更多關(guān)于android在mob平臺(tái)qq登陸和分享的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: qq
相關(guān)文章:
主站蜘蛛池模板: 云南省| 安国市| 巫山县| 乌拉特后旗| 礼泉县| 广水市| 尼玛县| 高邑县| 无棣县| 奉化市| 泰安市| 固始县| 松潘县| 武宁县| 图们市| 铁岭县| 平谷区| 彭州市| 和龙市| 义马市| 黎城县| 城固县| 安溪县| 新竹县| 富阳市| 金川县| 延川县| 白朗县| 寿阳县| 博兴县| 茌平县| 永吉县| 抚松县| 满洲里市| 宝应县| 无棣县| 民乐县| 阿城市| 聂荣县| 武强县| 南乐县|