当前位置: 首页 > news >正文

html网站分页怎么做的app开发流程

html网站分页怎么做的,app开发流程,分类网站怎么做seo,四川建设厅网上查询网站目录 ✅ 0. 需求 📂 1. 前言 🔱 2. 使用 2.1 账户体系前提 2.2 创建账户服务 2.3 操作账户-增删改查 💠 3. 源码流程 ✅ 0. 需求 试想,自己去实现一个账号管理体系,该如何做呢? ——————————…

目录

✅ 0. 需求

📂 1. 前言

🔱 2. 使用

2.1 账户体系前提

2.2 创建账户服务

2.3 操作账户-增删改查

💠 3. 源码流程


✅ 0. 需求

        试想,自己去实现一个账号管理体系,该如何做呢?

        ——————————

        最近有遇到这样一个需求:AR眼镜只支持同时与一个手机绑定,即:AR眼镜已与手机绑定过的话,不再支持与其他手机绑定;如要绑定其他手机,需要先解绑当前手机才能重新绑定。

        理解一下需求,即是:眼镜端需要账号管理体系,主要用来存储已绑定过手机的token。

        AR眼镜绑定手机时序图,如下所示:


 

📂 1. 前言

        我们知道,Android的账号管理体系是用来管理用户在Android设备上的身份验证和授权的系统,包括了对账号的创建、授权、修改和删除等操作的管理。

        那么,我们为什么要使用Android的账号管理体系?

        ——————————

        尽管,我们可以自己使用SP、MMKV、文件或数据库等方式来存储、更新、删除账户、密码或AuthToken;但其实涉及到跨进程通信,实现起来其实是稍显麻烦的;并且对于数据安全,信息加密这块的可靠性也有待商榷。

        另外,从本文第一张图可见,我们在架构设计中规划的账号体系服务,是寄生于Android启动时system_server开启的服务,然后通过binder方式,提供给其他进程使用。

        然而,在技术预研时发现,强大的Android早已想到了这点,在Android 2.0开始就加入了新包android.accounts,为我们准备好了这样一个服务ACCOUNT_SERVICE。

        而且,该包功能已十分强大,我们可以直接拿来使用,功能主要包括:

  1. 集中式的账户管理API,可以安全地存储和访问认证的令牌和密码;
  2. 可以在同一个设备中管理同一应用的多个不同账号,能够自动批量的同步服务器更新账户,甚至可以和不同服务器进行数据同步和安全认证;
  3. 把账户的验证过程、AuthToken的获取过程分离出来,降低程序的耦合性;
  4. 并且会在”设置”应用中添加一个账户入口;
  5. 方便应用间账号共享。

🔱 2. 使用

2.1 账户体系前提

        1)账号体系共享前提:使用相同的签名

        2)权限申明:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

2.2 创建账户服务

        步骤一:定义一个action为android.accounts.AccountAuthenticator的Intent的Service,并在meta-data的resource属性指定该Account基本显示信息的xml文件authenticator,模版代码如下:

<serviceandroid:name=".portal.feature.account.service.AccountService"android:enabled="true"android:exported="true"><intent-filter><action android:name="android.accounts.AccountAuthenticator" /></intent-filter><meta-dataandroid:name="android.accounts.AccountAuthenticator"android:resource="@xml/authenticator" />
</service>

        步骤二:在res下的xml文件夹中新建authenticator.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"android:accountType="com.agg.account"android:icon="@drawable/ic_test"android:label="AggAccount"android:smallIcon="@drawable/ic_test" />

        :android:accountType表示的是Account类型,它必须是唯一的,一般是包名。

        步骤三:创建继承自AbstractAccountAuthenticator的Authenticator文件,如下:

class Authenticator(context: Context) : AbstractAccountAuthenticator(context) {override fun editProperties(response: AccountAuthenticatorResponse?, accountType: String?): Bundle? {return null}override fun addAccount(response: AccountAuthenticatorResponse?,accountType: String?,authTokenType: String?,requiredFeatures: Array<out String>?,options: Bundle?): Bundle? {return null}override fun getAuthToken(response: AccountAuthenticatorResponse?,account: Account,authTokenType: String?,options: Bundle?): Bundle? {return null}override fun confirmCredentials(response: AccountAuthenticatorResponse?, account: Account?, options: Bundle?): Bundle? {return null}override fun getAuthTokenLabel(authTokenType: String?): String {return ""}override fun updateCredentials(response: AccountAuthenticatorResponse?,account: Account?,authTokenType: String?,options: Bundle?): Bundle? {return null}override fun hasFeatures(response: AccountAuthenticatorResponse?, account: Account?, features: Array<out String>?): Bundle? {return null}}

        步骤四:创建帐户Service,并在Service的onBind中调AbstractAccountAuthenticator的getIBinder()返回其用于远程调用的IBinder,如下所示:

class AccountService : Service() {private var authenticator: Authenticator? = nulloverride fun onCreate() {super.onCreate()authenticator = Authenticator(this)}override fun onBind(intent: Intent?): IBinder? {return authenticator?.iBinder}}

        :运行起来程序后,在“设置”应用-“帐户”-“添加帐户”列表中就已可以发现自己的app了。

2.3 操作账户-增删改查

        1)获取所有账号

    /*** 获取所有账号*/fun getAllAccount(context: Context) {val accountManager = context.getSystemService(Context.ACCOUNT_SERVICE) as AccountManagerLog.e(TAG, "getAllAccount: size = ${accountManager.accounts.size}")for (account in accountManager.accounts) {Log.e(TAG, "getAllAccount: $account")}}

         2)添加账号

    /*** 添加账号*/fun addAccount(context: Context, account: Account, password: String, authToken: String) {val bundle = Bundle()bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name)bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type)bundle.putString(AccountManager.KEY_AUTHTOKEN, authToken)bundle.putString(AccountManager.KEY_PASSWORD, password)AccountManager.get(context).addAccountExplicitly(account, password, bundle)}

         3)更新某个账号

    /*** 更新某个账号*/fun updateAccount(context: Context, account: Account, password: String = "", authToken: String = "") {var updatePassword = passwordvar updateAuthToken = authTokenAccountManager.get(context).apply {if (updatePassword.isEmpty()) {updatePassword = getUserData(account, AccountManager.KEY_PASSWORD)}if (updateAuthToken.isEmpty()) {updateAuthToken = getUserData(account, AccountManager.KEY_AUTHTOKEN)}removeAccountExplicitly(account)}addAccount(context, account, updatePassword, updateAuthToken)}

         4)删除某个账号

    /*** 删除某个账号*/fun delAccount(context: Context, account: Account) {val isRemoveSuccess = AccountManager.get(context).removeAccountExplicitly(account)Log.e(TAG, "delAllAccount: isRemoveSuccess = $isRemoveSuccess, $account")}

          5)删除所有账号

    /*** 删除所有账号*/fun delAllAccount(context: Context) {val accountManager = AccountManager.get(context)for (account in accountManager.accounts) {val isRemoveSuccess = accountManager.removeAccountExplicitly(account)Log.e(TAG, "delAllAccount: isRemoveSuccess = $isRemoveSuccess, $account")}}

💠 3. 源码流程

  • 从系统启动system_server进程,进而启动ACCOUNT_SERVICE服务开始;
  • AccountManager是一个面向应用程序开发的组件,它提供了一套对应于IAccountManager协议的应用程序接口;
  • 这组接口通过Binder机制与系统服务AccountManagerService进行通信,协作完成帐号相关的操作;
  • 同时AccountManager接收authenticators提供的回调,以便在帐号操作完成之后向调用此帐号服务的业务返回对应的接口,同时触发这个业务对结果的处理。

http://www.zhongyajixie.com/news/31402.html

相关文章:

  • 广州海珠网站制网络营销的有哪些特点
  • 西宁公司官方网站建设我想创建一个网络平台
  • 做企业网站需要的人腾讯3大外包公司
  • 用axure做网站建立网站用什么软件
  • web网站开发与管理央视新闻的新闻
  • 找个会做网站的 一起做网站怎么做网络销售
  • 楼市南京做凶宅的网站个人网站免费域名注册
  • 公司网站公司网站社群营销的十大步骤
  • 房子做水电的时候是不是要先埋网站360推广开户
  • 如何安装wordpress的插件北京seo服务商
  • wordpress好用的模板下载地址seo网站排名优化公司哪家
  • 柳城网站开发福建百度seo排名点击软件
  • 手机app开发用的是什么语言seo排名优化软件有用吗
  • 站长工具短链接生成seo入门教程网盘
  • 宁波营销型网站建设郑州做网站的大公司
  • 做网站需要做哪些东西快速排名提升
  • 青海网站建设怎么建设百度怎么推广自己的信息
  • 网站建设与管理难学吗nba实力榜最新排名
  • 如何做h5 网站seo排名资源
  • 织梦框架做网站简单怎么给自己的公司建立网站
  • 温州做网站制作哪家好优化搜索点击次数的方法
  • 西充县住房和城乡规划建设局网站移动建站模板
  • 店铺网站域名怎么做seo外链推广平台
  • 做网站能传电影网站多少钱游戏优化大师下载安装
  • 企业手机网站开发哪个网站做推广效果好
  • 公众平台网站开发哪家好最常用的搜索引擎有哪些
  • 怎么做网站投放广告的代理商百度网站排名seo
  • 空间查看网站腾讯广告推广平台入口
  • h5做网站教程seo搜索引擎优化推荐
  • 建设网站的技术方案是啥萧山市seo关键词排名