首页 文章 精选 留言 我的

精选列表

搜索[CI/CD集成],共10000篇文章
优秀的个人博客,低调大师

Android 应用程序集成Google 登录及二次封装

谷歌登录API: https://developers.google.com/identity/sign-in/android/ 1、注册并且登录google网站 https://accounts.google.com/ 2、进入google开发者平台创建应用 https://developers.google.com/mobile/add?platform=android&cntapi=signin&cntapp=Default%20Demo%20App&cntpkg=com.google.samples.quickstart.signin&cnturl=https:%2F%2Fdevelopers.google.com%2Fidentity%2Fsign-in%2Fandroid%2Fstart%3Fconfigured%3Dtrue&cntlbl=Continue%20with%20Try%20Sign-In 3、在开发者平台填写响应的信息,包括 应用名、包名、签名的SHA-1值 图1 图2 图3 4、在项目中添加谷歌服务 4.1、在SDK Manager 里面下载 google service 4.2、在project目录下的build.gradle下添加 classpath 'com.google.gms:google-services:2.1.0-alpha4' 查看最新版本号:https://jcenter.bintray.com/com/google/gms/google-services/ 4.3 在model目录下的build.gradle下添加 compile 'com.google.android.gms:play-services-auth:8.4.0' 5、代码实现 5.1、在布局文件中 1 <com.google.android.gms.common.SignInButton 2 android:id="@+id/google_signIn_bt" 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" /> 5 6 <Button 7 android:id="@+id/google_loginOut_bt" 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:text="google退出登录" 11 android:layout_gravity="center" 12 android:gravity="center" 13 > 14 </Button> 5.2、java代码 1 package com.pegasus.map.presentation.ui.activity; 2 3 import android.content.Intent; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.widget.Button; 7 8 import com.google.android.gms.auth.api.Auth; 9 import com.google.android.gms.auth.api.signin.GoogleSignInAccount; 10 import com.google.android.gms.auth.api.signin.GoogleSignInOptions; 11 import com.google.android.gms.auth.api.signin.GoogleSignInResult; 12 import com.google.android.gms.common.ConnectionResult; 13 import com.google.android.gms.common.SignInButton; 14 import com.google.android.gms.common.api.GoogleApiClient; 15 import com.google.android.gms.common.api.ResultCallback; 16 import com.google.android.gms.common.api.Status; 17 import com.pegasus.map.R; 18 import com.pegasus.map.presentation.ui.base.BaseActivity; 19 20 import butterknife.Bind; 21 import butterknife.ButterKnife; 22 23 /** 24 * Created by ${zyj} on 2016/3/24. 25 * 登录 26 */ 27 28 public class LoginActivity1 extends BaseActivity implements GoogleApiClient.OnConnectionFailedListener , View.OnClickListener { 29 30 public int RequestCode = 10 ; 31 32 @Bind( R.id.google_signIn_bt ) 33 public SignInButton google_signIn_bt ; 34 35 @Bind( R.id.google_loginOut_bt ) 36 public Button google_loginOut_bt ; 37 38 public GoogleSignInOptions gso ; 39 public GoogleApiClient mGoogleApiClient ; 40 41 @Override 42 protected void onCreate(Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 setContentView(R.layout.activity_login); 45 ButterKnife.bind(this); 46 init(); 47 } 48 49 50 private void init() { 51 //初始化谷歌登录服务 52 gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 53 .requestEmail() //获取邮箱 54 .requestId() //获取id 号 55 .requestIdToken("456212545785") //获取token 56 .build(); 57 58 // Build a GoogleApiClient with access to GoogleSignIn.API and the options above. 59 mGoogleApiClient = new GoogleApiClient.Builder( this ) 60 .enableAutoManage( this , this ) 61 .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 62 .build(); 63 64 //登录 65 google_signIn_bt.setSize(SignInButton.SIZE_STANDARD); 66 google_signIn_bt.setScopes(gso.getScopeArray()); 67 google_signIn_bt.setOnClickListener(this) ; 68 69 //退出 70 google_loginOut_bt.setOnClickListener(this) ; 71 72 } 73 74 @Override 75 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 76 super.onActivityResult(requestCode, resultCode, data); 77 78 //谷歌登录成功回调 79 if ( requestCode == RequestCode ) { 80 GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 81 handleSignInResult( result ) ; 82 } 83 } 84 85 @Override 86 public void onConnectionFailed(ConnectionResult connectionResult) { 87 88 } 89 90 @Override 91 public void onClick(View v) { 92 switch ( v.getId() ){ 93 case R.id.google_signIn_bt : //登录 94 signIn(); 95 break; 96 97 case R.id.google_loginOut_bt : 98 signOut(); 99 break; 100 } 101 } 102 103 /** 104 * 登录 105 */ 106 private void signIn() { 107 Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 108 startActivityForResult(signInIntent, RequestCode ); 109 } 110 111 /** 112 * 退出 113 */ 114 private void signOut() { 115 Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback( 116 new ResultCallback<Status>() { 117 @Override 118 public void onResult(Status status) { 119 // ... 120 } 121 }); 122 } 123 124 private void handleSignInResult(GoogleSignInResult result) { 125 if (result.isSuccess()) { 126 // Signed in successfully, show authenticated UI. 127 GoogleSignInAccount acct = result.getSignInAccount(); 128 //获取用户名 129 String name = acct.getDisplayName() ; 130 String email = acct.getEmail() ; 131 String token = acct.getIdToken() ; 132 String id = acct.getId() ; 133 134 } else { 135 // Signed out, show unauthenticated UI. 136 } 137 } 138 139 } 6、Google SDK 二次封装 1 package com.pegasus.map.presentation.utils; 2 3 import android.content.Intent; 4 import android.support.v4.app.FragmentActivity; 5 import android.util.Log; 6 import android.widget.Toast; 7 8 import com.google.android.gms.auth.api.Auth; 9 import com.google.android.gms.auth.api.signin.GoogleSignInAccount; 10 import com.google.android.gms.auth.api.signin.GoogleSignInOptions; 11 import com.google.android.gms.auth.api.signin.GoogleSignInResult; 12 import com.google.android.gms.common.api.GoogleApiClient; 13 import com.google.android.gms.common.api.ResultCallback; 14 import com.google.android.gms.common.api.Status; 15 import com.pegasus.map.R; 16 17 /** 18 * Created by ${zyj} on 2016/3/30. 19 */ 20 public class GoogleLogin { 21 22 public int requestCode = 10 ; 23 private FragmentActivity activity ; 24 public GoogleSignInOptions gso ; 25 public GoogleApiClient mGoogleApiClient ; 26 public GoogleApiClient.OnConnectionFailedListener listener ; 27 private GoogleSignListener googleSignListener ; 28 29 public GoogleLogin(FragmentActivity activity , GoogleApiClient.OnConnectionFailedListener listener ){ 30 this.activity = activity ; 31 this.listener = listener ; 32 33 //初始化谷歌登录服务 34 gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 35 .requestEmail() 36 .requestId() 37 .requestIdToken( activity.getString(R.string.google_server_client_id)) 38 .requestProfile() 39 .build(); 40 41 // Build a GoogleApiClient with access to GoogleSignIn.API and the options above. 42 mGoogleApiClient = new GoogleApiClient.Builder( activity ) 43 .enableAutoManage( activity , listener ) 44 .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 45 .build(); 46 } 47 48 49 /** 50 * 登录 51 */ 52 public void signIn() { 53 Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 54 activity.startActivityForResult(signInIntent, requestCode); 55 } 56 57 /** 58 * 退出登录 59 */ 60 public void signOut() { 61 Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback( 62 new ResultCallback<Status>() { 63 @Override 64 public void onResult(Status status) { 65 if ( status.isSuccess() ){ 66 if ( googleSignListener != null ){ 67 googleSignListener.googleLogoutSuccess(); 68 } 69 }else { 70 if ( googleSignListener!= null ){ 71 googleSignListener.googleLogoutFail(); 72 } 73 } 74 } 75 }); 76 } 77 78 public String handleSignInResult(GoogleSignInResult result) { 79 String res = "" ; 80 if (result.isSuccess()) { 81 //登录成功 82 GoogleSignInAccount acct = result.getSignInAccount(); 83 res = "登录成功" 84 + "用户名为:" + acct.getDisplayName() 85 + " 邮箱为:" + acct.getEmail() 86 + " token为:" + acct.getIdToken() 87 + " 头像地址为:" + acct.getPhotoUrl() 88 + " Id为:" + acct.getId() 89 + " GrantedScopes为:" + acct.getGrantedScopes() ; 90 Log.e("res", "res:"+res); 91 Toast.makeText( activity, res, Toast.LENGTH_SHORT).show(); 92 if ( googleSignListener != null ){ 93 googleSignListener.googleLoginSuccess(); 94 } 95 } else { 96 // Signed out, show unauthenticated UI. 97 res = "-1" ; //-1代表用户退出登录了 , 可以自定义 98 Toast.makeText( activity , "退出登录", Toast.LENGTH_SHORT).show(); 99 if ( googleSignListener != null ){ 100 googleSignListener.googleLoginFail(); 101 } 102 } 103 return res ; 104 } 105 106 107 public void setGoogleSignListener( GoogleSignListener googleSignListener ){ 108 this.googleSignListener = googleSignListener ; 109 } 110 111 public interface GoogleSignListener { 112 void googleLoginSuccess(); 113 void googleLoginFail() ; 114 void googleLogoutSuccess(); 115 void googleLogoutFail() ; 116 } 117 118 } 注意:当你把 GoogleLogin 类复制到你项目中的时候,activity.getString(R.string.google_server_client_id) 这一句会报错,可以先不用管,在6.5 部分会做说明 6.1 在activity里使用封装类 activity 实现 GoogleApiClient.OnConnectionFailedListener , GoogleLogin.GoogleSignListener 两个接口 6.2 //初始化谷歌登录服务 GoogleLogin googleLogin = new GoogleLogin( this , this ) ; googleLogin.setGoogleSignListener(this); 6.3 1 @Override 2 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 3 super.onActivityResult(requestCode, resultCode, data); 4 5 //谷歌登录成功回调 6 if (requestCode == googleLogin.requestCode ) { 7 GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 8 googleLogin.handleSignInResult( result ) ; 9 } 10 } 6.4 1 //登录 2 googleLogin.signIn(); 3 4 //退出 5 googleLogin.signOut(); 6.5 获取google_server_client_id , 并在strings 里面配置 https://console.developers.google.com/projectselector/apis/credentials 在上面的网站里选择 点击选择项目,然后选择你创建的app,进入下面一个界面,得到对应的Client ID 补充:(2016/8/9) 有很多人留言或者发私信说一直登陆失败。然后我就自己写了一个demo,核心代码完全复制博客里面的GoogleLogin (代码见第六个标题,6、Google SDK 二次封装) 里面的代码,真的是一行代码都没有改,完完全全复制的。最后实现登陆成功,可见博客里面的代码是没有问题的。我在操作过程中,有几个关键的地方提一下。 1、权限问题 只需要添加联网权限即可 <uses-permission android:name="android.permission.INTERNET"></uses-permission> 2、签名问题 在开发者后台创建app的时候,需要添加 SHA-1的值,这个值是从你的签名里面获取的。注意,在你运行demo的时候,如果直接运行是不行的,因为直接运行,android studio 会为你的app使用默认签名,这个签名是系统自带的,这个签名的SHA-1值肯定和你真正的签名文件SHA-1值不一样,所以必然会登录失败。 你需要修改你的app debug 时的签名和 发布时的签名一直就好了。

优秀的个人博客,低调大师

weex sdk集成到Android工程三. weex服务项目搭建

1. 前言 前面介绍了app本地调用js的方式(js文件放在assert目录下面),其实大部分都是调用远程js,本篇介绍app如何调用远程js文件。 2.服务项目搭建步骤 前提需要安装好weex环境,具体参见前面文章:环境搭建地址 接下来讲解如何使用weex-toolkit构建项目: 1)创建项目: 命令行到任意文件夹,输入如下指令 weex init 1 1 执行指令后,会看到如图所示的信息: 此时你会在你的文件夹下面看到如下所示的目录结构: 2)安装npm依赖 命令行下面继续输入如下指令 // 安装依赖包,安装成功后,会增加一个node_modules包 npm install 1 2 1 2 3)启动serve 我们首先看一下package.json下的指令 "build": "webpack",// build 配置 "dev": "webpack --watch",// webpack 监听,可以自动监听修改 "serve": "serve -p 8080",// 启动服务 "test": "echo \"Error: no test specified\" && exit 1" 1 2 3 4 1 2 3 4 执行,如下指令: npm run build 1 1 npm run serve 1 1 成功后,日志如下图所示 我们在浏览器中输入localhost:8080查看效果吧。 很明显,在浏览器中正确展示了,但是最终要在手机中展现。 3.app中远程调用该js 调用代码改成如下所示 mWXSDKInstance.renderByUrl("MyApplication","http://10.25.52.72:8080/dist/main.js",null, null, -1, -1, WXRenderStrategy.APPEND_ASYNC); 1 1 运行app程序,界面如下图所示: 接下来就是要体验动态改变的功能了,很简单,改变服务项目中的.we文件 执行如下指令: npm run build 1 1 npm run serve 1 1 成功后,在打开app,你会发现如图所示: 是不是很强,类似动态部署。

优秀的个人博客,低调大师

QGIS基于规则的道路分级制图及Leaflet集成展示实例

在当今数字化时代,地理信息系统的应用日益广泛,而地图作为地理信息的重要可视化载体,其重要性不言而喻。道路作为城市和区域交通网络的核心组成部分,其可视化表达对于交通规划、城市管理和公众出行等众多领域都有着极为关键的作用。然而,面对复杂的道路数据,如何高效、准确且美观地进行分级制图,并将其以一种便捷、交互性强的方式呈现给用户,是地理信息工作者面临的重要挑战之一。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码