Commit a4e8a4b1 authored by shiyl's avatar shiyl

add 集成友盟三方登录,实现微信授权

parent 3f8d4d0c
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.yidian.common"> package="com.yidian.common">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<!-- 以下为友盟分享基本配置信息 start-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${file_provider}"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
<!--微信分享/登录-->
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true">
<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="tencent101923771" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
<!-- 以上为友盟分享基本配置信息 end-->
</application>
</manifest> </manifest>
package com.yidian.common.utils
import android.app.Activity
import com.umeng.socialize.UMAuthListener
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import com.yidian.utils.ToastUtil
/**
* 授权登录工具类
*/
object AuthUtils {
/**
* 校验是否已经授权
*/
fun checkIsAuth(activity: Activity, platform: SHARE_MEDIA): Boolean {
return UMShareAPI.get(activity).isAuthorize(activity, platform)
}
/**
* 进行平台授权
*
* @return 返回授权信息的map
*/
fun toAuthorize(activity: Activity, platform: SHARE_MEDIA): Map<String, String> {
var authMap: Map<String, String> = HashMap()
UMShareAPI.get(activity).getPlatformInfo(activity, platform, object : UMAuthListener {
override fun onStart(share_media: SHARE_MEDIA) {}
override fun onComplete(share_media: SHARE_MEDIA, i: Int, map: Map<String, String>) {
authMap = map
}
override fun onError(share_media: SHARE_MEDIA, i: Int, throwable: Throwable) {
ToastUtil.showToast(activity, throwable.message)
}
override fun onCancel(share_media: SHARE_MEDIA, i: Int) {
ToastUtil.showToast(activity, "用户已取消")
}
})
return authMap
}
}
...@@ -5,19 +5,22 @@ import android.content.pm.ApplicationInfo ...@@ -5,19 +5,22 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.util.Log import android.util.Log
/**
* 检查APK是否安装
*/
class CheckApkExistUtil { class CheckApkExistUtil {
companion object{ companion object {
const val weChatPkgName = "com.tencent.mm" const val weChatPkgName = "com.tencent.mm"
const val mobileQQPkgName = "com.tencent.mobileqq" const val mobileQQPkgName = "com.tencent.mobileqq"
const val sinaBlogPkgName = "com.sina.weibo" const val sinaBlogPkgName = "com.sina.weibo"
fun checkApkExist(context: Context, packageName: String): Boolean{ fun checkApkExist(context: Context, packageName: String): Boolean {
if(packageName.isEmpty()) return false if (packageName.isEmpty()) return false
var packageInfo: ApplicationInfo? val packageInfo: ApplicationInfo? = try {
try { context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)
packageInfo = context.packageManager.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES) } catch (e: PackageManager.NameNotFoundException) {
}catch (e: PackageManager.NameNotFoundException){ null
packageInfo = null
} }
return packageInfo != null return packageInfo != null
} }
......
...@@ -5,14 +5,14 @@ import android.net.ConnectivityManager ...@@ -5,14 +5,14 @@ import android.net.ConnectivityManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
class NetWorkUtils { class NetWorkUtils {
companion object{ companion object {
const val NET_TYPE_WIFI = "wifi" private const val NET_TYPE_WIFI = "wifi"
const val NET_TYPE_4G = "4g" const val NET_TYPE_4G = "4g"
const val NET_TYPE_5G = "5g" const val NET_TYPE_5G = "5g"
const val NET_TYPE_3G = "3g" const val NET_TYPE_3G = "3g"
const val NET_TYPE_2G = "2g" const val NET_TYPE_2G = "2g"
fun getNetWorkType(context: Context): String{ fun getNetWorkType(context: Context): String {
var netType = "unknown" var netType = "unknown"
val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = manager.activeNetworkInfo ?: return netType val networkInfo = manager.activeNetworkInfo ?: return netType
...@@ -22,15 +22,17 @@ class NetWorkUtils { ...@@ -22,15 +22,17 @@ class NetWorkUtils {
} else if (nType == ConnectivityManager.TYPE_MOBILE) { } else if (nType == ConnectivityManager.TYPE_MOBILE) {
val nSubType = networkInfo.subtype val nSubType = networkInfo.subtype
val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager val telephonyManager: TelephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
netType = if(nSubType ==TelephonyManager.NETWORK_TYPE_NR){ netType = if (nSubType == TelephonyManager.NETWORK_TYPE_NR) {
"5g" "5g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) { } else if (nSubType == TelephonyManager.NETWORK_TYPE_LTE && !telephonyManager.isNetworkRoaming) {
"4g" "4g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0 } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA || (nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming)) { && !telephonyManager.isNetworkRoaming)
) {
"3g" "3g"
} else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS || nSubType == TelephonyManager.NETWORK_TYPE_EDGE || (nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming)) { && !telephonyManager.isNetworkRoaming)
) {
"2g" "2g"
} else { } else {
"unknown" "unknown"
...@@ -38,7 +40,8 @@ class NetWorkUtils { ...@@ -38,7 +40,8 @@ class NetWorkUtils {
} }
return netType return netType
} }
fun isWifiConnected(context: Context):Boolean{
fun isWifiConnected(context: Context): Boolean {
return NET_TYPE_WIFI == getNetWorkType(context) return NET_TYPE_WIFI == getNetWorkType(context)
} }
} }
......
package com.yidian.common.utils
import android.content.Context
/**
* 分享工具类
*/
object ShareUtils {
}
...@@ -65,9 +65,9 @@ object ToolsUtil { ...@@ -65,9 +65,9 @@ object ToolsUtil {
} }
//格式化展示 //格式化展示
fun formatShowNum(count: Int): String{ fun formatShowNum(count: Int): String {
var showCount = count.toString() var showCount = count.toString()
when{ when {
count in 1000..9999 -> { count in 1000..9999 -> {
val floutCount = count / 1000 val floutCount = count / 1000
showCount = floutCount.toString().format("%.1f") + "K" showCount = floutCount.toString().format("%.1f") + "K"
...@@ -160,12 +160,12 @@ object ToolsUtil { ...@@ -160,12 +160,12 @@ object ToolsUtil {
return mask return mask
} }
fun saveImage(bitmap: Bitmap, name: String, context: Context):Boolean { fun saveImage(bitmap: Bitmap, name: String, context: Context): Boolean {
try { try {
val sdcardPath = System.getenv("EXTERNAL_STORAGE") val sdcardPath = System.getenv("EXTERNAL_STORAGE")
val dir = "$sdcardPath/life_circle_business/" val dir = "$sdcardPath/life_circle_business/"
val file = File(dir) val file = File(dir)
if (!file.exists()){ if (!file.exists()) {
file.mkdirs() file.mkdirs()
} }
......
package com.yidian.common.wxapi
import com.umeng.socialize.weixin.view.WXCallbackActivity
class WXEntryActivity : WXCallbackActivity() {
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<paths> <paths>
<external-files-path name="umeng_cache" path="umeng_cache/"/> <!--友盟微信分享SDK 共享路径 -->
<external-files-path name="opensdk_external" path="Images/tmp"/> <external-files-path
<root-path name="opensdk_root" path=""/> name="umeng_cache"
<external-cache-path name="video_cache" path="video_cache/"/> path="umeng_cache/" />
<external-cache-path name="ocr" path="ocr" /> <!-- QQ 官方分享SDK 共享路径 -->
<external-files-path
name="opensdk_external"
path="Images/tmp" />
<root-path
name="opensdk_root"
path="" />
<!-- 新浪微博分享SDK 共享路径-->
<external-files-path
name="share_files"
path="." />
<external-cache-path
name="video_cache"
path="video_cache/" />
<external-cache-path
name="ocr"
path="ocr" />
</paths> </paths>
\ No newline at end of file
...@@ -39,59 +39,12 @@ ...@@ -39,59 +39,12 @@
tools:replace="android:allowBackup,android:label" tools:replace="android:allowBackup,android:label"
tools:targetApi="n"> tools:targetApi="n">
<!-- 以下为友盟分享基本配置信息 start-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${file_provider}"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
<uses-library <uses-library
android:name="org.apache.http.legacy" android:name="org.apache.http.legacy"
android:required="false" /> android:required="false" />
<activity
android:name="com.yidian.common.wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true">
<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="tencent101923771" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
<!-- 以上为友盟分享基本配置信息 end-->
<!-- Flutter图片裁剪相册--> <!-- Flutter图片裁剪相册-->
<activity <activity
android:name="com.yalantis.ucrop.UCropActivity" android:name="com.yalantis.ucrop.UCropActivity"
......
...@@ -9,7 +9,9 @@ buildscript { ...@@ -9,7 +9,9 @@ buildscript {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' } maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" } maven { url "https://dl.bintray.com/thelasterstar/maven/" }
} }
dependencies { dependencies {
...@@ -28,7 +30,9 @@ allprojects { ...@@ -28,7 +30,9 @@ allprojects {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven { url "https://www.jitpack.io" } maven { url "https://www.jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' } maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" } maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url "http://dailybuild2.yidian-inc.com:8088/repository/maven-public/" } maven { url "http://dailybuild2.yidian-inc.com:8088/repository/maven-public/" }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment