首页 文章 精选 留言 我的

精选列表

搜索[TDSQL PostgreSQL 版],共10000篇文章
优秀的个人博客,低调大师

配置云存储网关在线服务支持多个互联VPC-高速通道版

1 概述 云存储网关是一款帮助客户在现有本地应用程序、基础设施和数据存储与阿里云之间实现无缝集成的存储服务。通过可在本地和云上部署的兼容行业标准存储协议的虚拟设备,将现有的存储应用程序和工作负载链接阿里云存储服务,无缝对接阿里云的存储和计算服务。 目前公测中的云存储网关服务,把网关服务的部署和资源配置做了自动化部署,大大简化了使用流程,方便用户使用。云存储网关服务可以自动适配用户在VPC内的ECS客户端,打通网络层面配置。但是阿里云公网里有大量的企业客户的采用多个VPC互联的方式支持大规模ECS集群。云存储网关服务在1.0.31及以前,只支持单个VPC的ECS实例链接,不支持多个VPC互联。从1.0.32云存储网关服务增加了对多个VPC网段的支持,目前可以同时支持阿里云标准VPC的所有网段:192.168.0.0/16, 17

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

【Sigma敏捷版系列文章】如何利用apiserver-builder自定义Kubernetes API

背景知识 了解一下k8s API k8s中的API可以抽象为两个阶段:存储和调和。存储(Storage):Kubernetes API公开了用于存储声明期望集群状态的资源对象的操作调和(Reconciliation):通常称为控制器(controller)的进程集合监视写入资源的对象进行调和如图:API具有如下特征:1、Declarative(声明式)Kubernetes API被设计为:对象的期望状态被发送到API服务器,该服务器集群用于协调实际状态与期望的状态2、Level based (基于等级)基于等级的实现会依据当前最新的状态,而忽略先前的期望状态。例如执行Deployment更新镜像的时候,如果当前设置的是镜像A没有更新完成时,这时候又更新Deployment设置为镜像B,则会按照最新的B进行更新。3、Asynchrono

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

使用 Ruff 开发板+ Link Develop 快速开发 IoT 应用(环境预配置版)

0. 成果 1. 前期准备 开通 Link Develop 账号:使用阿里云账号或者淘宝账号访问 https://linkdevelop.aliyun.com/,填写开发者入驻表单完成入驻。(即申请即通过) 依赖安装:已预先配置完成。 项目文件创建与生成:已预先配置完成。 Ruff 硬件开发 一、上云 此步操作设备:电脑 登录阿里云账号,访问 https://linkdevelop.aliyun.com 创建一个新项目: 从项目控制台左侧的设备菜单项里找到“产品开发”,点击进入并点击“立即创建产品”。 按下图填写表单,所属分类选择“智能生活/电工照明/灯”,节点类型选择“设备”,通讯网络选择“Wi-Fi”,数据格式选择“Alink”,然后点“提交”后点击“进入开发”按钮。 添加一个 RGB 调色的功能定义:点击标准功能一栏右侧的“新增”按钮。在弹出的“

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

吴恩达深度学习中文版笔记:人脸识别和神经风格转换

自2016年8月份,吴恩达的初创公司deeplearning.ai通过Coursera提供深度学习的最新在线课程,到今年2月份,吴老师更新了课程的第五部分(点击查看大数据文摘相关报道),前后耗时半年时间。 本文将着重介绍吴恩达老师第四周课程的视频内容和笔记,展示一些重要的卷积神经网络的特殊应用,我们将从人脸识别开始,之后讲神经风格迁移,你将有机会在编程作业中实现这部分内容,创造自己的艺术作品。 什么是人脸识别? 让我们先从人脸识别开始,我这里有一个有意思的演示。我在领导百度AI团队的时候,其中一个小组由林元庆带领的,做过一个人脸识别系统,这个系统非常棒,让我们来看一下。 以下内容为演示视频内容: 视频开始: 我想演示一个人脸识别系统,我现在在百度的中国总部,很多公司要求进入公司的时候要刷工卡,但是在这里我们并不需要它,使用人脸识别,看看我能做

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

一个简单的C#+arcgis的非数据库版例子

1.首先新建一个winform的项目。 2.确保C#工具箱包含ESRI的相关控件,如果没有就需要安装SDK。 如果VS中依旧不存在esri控件解决方案如下,以VS2013为例: (1)打开注册表,定位至HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0,点击10.0在右侧空白处右侧新建--字符串值,名称取”InstallDir“,类型默认为REG_SZ,其数据值即为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0\InstallDir的值,也就是你VS2013的安装路径。 (2)win7 64位下只要把vs2010安装目录下\Common7\IDE\ItemTemplates\CSharp\ArcGIS文件夹和\Common7\IDE\ProjectTemplates\CSharp\ArcGIS分别对应复制到C:\Users\Administrator\Documents\Visual Studio 2013\Templates\ItemTemplates\Visual C#和C:\Users\Administrator\Documents\Visual Studio 2013\Templates\ProjectTemplates\Visual C#就可以了。 (3)重启VS后还没有那就手动添加一下吧! 3.将VS的相应ToolbarControl(工具控件),AxTOCControl(目录控件),AxMapControl(地图控件)和AxLicenseControl (许可控件)控件拖到界面形成一下效果: 之后修改public Form1()的后台代码如下: ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop); InitializeComponent(); string path = @"F:\Chang\mapTest\mapTest\World\"; string fileName = @"World.mxd"; //加载图层文件 axMapControl1.LoadMxFile(path + fileName); //设置MapControl显示范围到数据的全局范围 axMapControl1.Extent = axMapControl1.FullExtent; 运行效果最终形成 源码下载

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

“中国版特斯拉”绝地反击,自动驾驶开辟“第三条路”?

马斯克最近可以不用睡在工厂了。 不久前,中国宣布将相当幅度降低汽车进口关税,很可能将整车关税从目前的25%降低到15%,以特斯拉为代表的美国车企将直接因此受益。 但对中国车企来说,降税带来竞争结果并非全是挑战,况且,在特斯拉们进门之前,现在正是黄金窗口期:一方面,新关税的制定需要落地时间和执行过程;另一方面,特斯拉本身产能不足,尤其是“平民款”Model 3车型交付遥遥无期,因此马斯克也只能睡在工厂当“监工”。 下周,北京车展将开幕,这是中国2018年的第一个大展,在中美贸易关系微妙的背景下,国内车企的主打车的高性能、低价格,更像是一次集体秀肌肉。 进口汽车关税降幅或达40%,中国车企北京车展趁机反击 在刚刚结束的博鳌亚洲论坛上,国家领导人承诺对进口汽车降低关税。 汽车行业分析师张毅在接受《环球时报》记者采访时预测称,综合各种因素考虑,中国很

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

SSM-SpringMVC-26:SpringMVC异常骇级之自定义异常注解版

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 注解的方法实现异常解析,话不多说,直接搞起,和以前一样的习惯,和上篇博客一样的代码放后面,不一样的在前面 案例: 1.自定义处理器和处理方法 package cn.dawn.day18annotationexception; import cn.dawn.day18annotationexception.userexception.UserageException; import cn.dawn.day18annotationexception.userexception.UsernameException; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Created by Dawn on 2018/3/28. */ @Controller public class ZDYExceptionController { /*作用于这俩个*/ @ExceptionHandler({UsernameException.class,UserageException.class}) public ModelAndView resolveException(Exception ex) { ModelAndView modelAndView=new ModelAndView(); /*返回的异常对象*/ modelAndView.addObject("ex",ex); /*判断去那个页面*/ if(ex instanceof UsernameException){ modelAndView.setViewName("name"); } if(ex instanceof UserageException){ modelAndView.setViewName("age"); } return modelAndView; } @RequestMapping("/annotationException") public String annotationException(String username,Integer userage) throws Exception { if(!username.equals("admin")){ throw new UsernameException("登陆名不正确"); } if(userage<18){ throw new UserageException("未成年,走开"); } return "success"; } } 2.自己的xml大配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--包扫描器--> <context:component-scan base-package="cn.dawn.day18annotationexception"></context:component-scan> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/day18/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans> 3.修改web.xml的中央调度器的上下文配置路径 4.login.jsp <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h2>登录</h2> <form action="${pageContext.request.contextPath}/annotationException" method="post"> 用户名:<input name="username"> 年龄:<input name="userage"> <input type="submit" value="登录"/> </form> </body> </html> 下面的内容与上篇博客相同 5.UserageException自定义异常 package cn.dawn.day17selfexceptionresolver.userexception; /** * Created by Dawn on 2018/3/30. */ public class UserageException extends Exception { public UserageException() { super(); } public UserageException(String message) { super(message); } } 6.UsernameException自定义异常 package cn.dawn.day17selfexceptionresolver.userexception; /** * Created by Dawn on 2018/3/30. */ public class UsernameException extends Exception { public UsernameException() { super(); } public UsernameException(String message) { super(message); } } 7.jsp页面 7.1success.jsp <%@ page language="java" pageEncoding="utf-8" isELIgnored="false" %> <html> <body> <%--<img src="image/1.jpg">--%> <h2>Success!</h2> </body> </html> 7.2error.jsp <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h2>ERROR</h2> <p>${ex.message}</p> 服务器被猴子砍了,攻城狮在抢修中,还杀了个程序猿祭天 </body> </html> 7.3age.jsp <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h2>年龄错误ERROR</h2> <p>${ex.message}</p> 服务器被猴子砍了,攻城狮在抢修中,还杀了个程序猿祭天 </body> </html> 7.4name.jsp <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h2>名字错误ERROR</h2> <p>${ex.message}</p> 服务器被猴子砍了,攻城狮在抢修中,还杀了个程序猿祭天 </body> </html> 8.启动tomcat,访问login.jsp

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

Android版:验证手机号码的正则表达式 (转)

/** * 验证手机格式 */ public static boolean isMobileNO(String mobiles) { /* 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 联通:130、131、132、152、155、156、185、186 电信:133、153、180、189、(1349卫通) 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9 */ String telRegex = "[1][358]\\d{9}";//"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。 if (TextUtils.isEmpty(mobiles)) return false; else return mobiles.matches(telRegex); } 转自:链接 本文转自SharkBin博客园博客,原文链接:http://www.cnblogs.com/SharkBin/p/5237495.html,如需转载请自行联系原作者

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

Android第十三期 - 百度云推送(百度后台版)

这回比较费事儿,我给学弟学妹分解一下,下面开始: 配置部分: 1.去百度云推送注册账号,配置一下,如图: 2.点击消息跳转的配置部分,如图: 3.发送消息的配置,如图: 这样就完成百度后台的发送消息的服务器的配置了。 接着是App的代码部分: 1.MyPushMessageReceiver: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 package com.baidu.push.example; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.content.Intent; import android.text.TextUtils; import android.util.Log; import com.baidu.frontia.api.FrontiaPushMessageReceiver; /** *Push消息处理receiver。请编写您需要的回调函数,一般来说:onBind是必须的,用来处理startWork返回值; *onMessage用来接收透传消息;onSetTags、onDelTags、onListTags是tag相关操作的回调; *onNotificationClicked在通知被点击时回调;onUnbind是stopWork接口的返回值回调 * *返回值中的errorCode,解释如下: *0-Success *10001-NetworkProblem *30600-InternalServerError *30601-MethodNotAllowed *30602-RequestParamsNotValid *30603-AuthenticationFailed *30604-QuotaUseUpPaymentRequired *30605-DataRequiredNotFound *30606-RequestTimeExpiresTimeout *30607-ChannelTokenTimeout *30608-BindRelationNotFound *30609-BindNumberTooMany * *当您遇到以上返回错误时,如果解释不了您的问题,请用同一请求的返回值requestId和errorCode联系我们追查问题。 * */ public class MyPushMessageReceiver extends FrontiaPushMessageReceiver{ /**TAGtoLog*/ public static final StringTAG=MyPushMessageReceiver. class .getSimpleName(); /** *调用PushManager.startWork后,sdk将对push *server发起绑定请求,这个过程是异步的。绑定请求的结果通过onBind返回。如果您需要用单播推送,需要把这里获取的channel *id和userid上传到应用server中,再调用server接口用channelid和userid给单个手机或者用户推送。 * *@paramcontext *BroadcastReceiver的执行Context *@paramerrorCode *绑定接口返回值,0-成功 *@paramappid *应用id。errorCode非0时为null *@paramuserId *应用userid。errorCode非0时为null *@paramchannelId *应用channelid。errorCode非0时为null *@paramrequestId *向服务端发起的请求id。在追查问题时有用; *@returnnone */ @Override public void onBind(Contextcontext, int errorCode,Stringappid, StringuserId,StringchannelId,StringrequestId){ StringresponseString= "onBinderrorCode=" +errorCode+ "appid=" +appid+ "userId=" +userId+ "channelId=" +channelId + "requestId=" +requestId; Log.d(TAG,responseString); //绑定成功,设置已绑定flag,可以有效的减少不必要的绑定请求 if (errorCode== 0 ){ Utils.setBind(context, true ); } //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,responseString); } /** *接收透传消息的函数。 * *@paramcontext *上下文 *@parammessage *推送的消息 *@paramcustomContentString *自定义内容,为空或者json字符串 */ @Override public void onMessage(Contextcontext,Stringmessage, StringcustomContentString){ StringmessageString= "透传消息message=\"" +message + "\"customContentString=" +customContentString; Log.d(TAG,messageString); //自定义内容获取方式,mykey和myvalue对应透传消息推送时自定义内容中设置的键和值 if (!TextUtils.isEmpty(customContentString)){ JSONObjectcustomJson= null ; try { customJson= new JSONObject(customContentString); Stringmyvalue= null ; if (customJson.isNull( "mykey" )){ myvalue=customJson.getString( "mykey" ); } } catch (JSONExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,messageString); } /** *接收通知点击的函数。注:推送通知被用户点击前,应用无法通过接口获取通知的内容。 * *@paramcontext *上下文 *@paramtitle *推送的通知的标题 *@paramdescription *推送的通知的描述 *@paramcustomContentString *自定义内容,为空或者json字符串 */ @Override public void onNotificationClicked(Contextcontext,Stringtitle, Stringdescription,StringcustomContentString){ StringnotifyString= "通知点击title=\"" +title+ "\"description=\"" +description+ "\"customContent=" +customContentString; Log.d(TAG,notifyString); //自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值 if (!TextUtils.isEmpty(customContentString)){ JSONObjectcustomJson= null ; try { customJson= new JSONObject(customContentString); Stringmyvalue= null ; if (customJson.isNull( "mykey" )){ myvalue=customJson.getString( "mykey" ); } } catch (JSONExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,notifyString); } /** *setTags()的回调函数。 * *@paramcontext *上下文 *@paramerrorCode *错误码。0表示某些tag已经设置成功;非0表示所有tag的设置均失败。 *@paramsuccessTags *设置成功的tag *@paramfailTags *设置失败的tag *@paramrequestId *分配给对云推送的请求的id */ @Override public void onSetTags(Contextcontext, int errorCode, List<String>sucessTags,List<String>failTags,StringrequestId){ StringresponseString= "onSetTagserrorCode=" +errorCode + "sucessTags=" +sucessTags+ "failTags=" +failTags + "requestId=" +requestId; Log.d(TAG,responseString); //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,responseString); } /** *delTags()的回调函数。 * *@paramcontext *上下文 *@paramerrorCode *错误码。0表示某些tag已经删除成功;非0表示所有tag均删除失败。 *@paramsuccessTags *成功删除的tag *@paramfailTags *删除失败的tag *@paramrequestId *分配给对云推送的请求的id */ @Override public void onDelTags(Contextcontext, int errorCode, List<String>sucessTags,List<String>failTags,StringrequestId){ StringresponseString= "onDelTagserrorCode=" +errorCode + "sucessTags=" +sucessTags+ "failTags=" +failTags + "requestId=" +requestId; Log.d(TAG,responseString); //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,responseString); } /** *listTags()的回调函数。 * *@paramcontext *上下文 *@paramerrorCode *错误码。0表示列举tag成功;非0表示失败。 *@paramtags *当前应用设置的所有tag。 *@paramrequestId *分配给对云推送的请求的id */ @Override public void onListTags(Contextcontext, int errorCode,List<String>tags, StringrequestId){ StringresponseString= "onListTagserrorCode=" +errorCode+ "tags=" +tags; Log.d(TAG,responseString); //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,responseString); } /** *PushManager.stopWork()的回调函数。 * *@paramcontext *上下文 *@paramerrorCode *错误码。0表示从云推送解绑定成功;非0表示失败。 *@paramrequestId *分配给对云推送的请求的id */ @Override public void onUnbind(Contextcontext, int errorCode,StringrequestId){ StringresponseString= "onUnbinderrorCode=" +errorCode + "requestId=" +requestId; Log.d(TAG,responseString); //解绑定成功,设置未绑定flag, if (errorCode== 0 ){ Utils.setBind(context, false ); } //Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 updateContent(context,responseString); } private void updateContent(Contextcontext,Stringcontent){ Log.d(TAG, "updateContent" ); StringlogText= "" +Utils.logStringCache; if (!logText.equals( "" )){ logText+= "\n" ; } SimpleDateFormatsDateFormat= new SimpleDateFormat( "HH-mm-ss" ); logText+=sDateFormat.format( new Date())+ ":" ; logText+=content; Utils.logStringCache=logText; Intentintent= new Intent(); intent.setClass(context.getApplicationContext(),PushDemoActivity. class ); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.getApplicationContext().startActivity(intent); } } 注意:这里面的方法onMessage和onNotificationClicked可以自定义消息的显示样式。 2.要跳转到的MainActivity: 1 2 3 4 5 6 7 8 9 10 11 12 package com.baidu.push.example; import com.gaoxiaotongctone.R; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity{ @Override protected void onCreate(BundlesavedInstanceState){ //TODOAuto-generatedmethodstub super .onCreate(savedInstanceState); setContentView(R.layout.custom_activity); } } 3.主窗体PushDemoActivity的显示: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 package com.baidu.push.example; import java.util.Calendar; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.app.Notification; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.util.Log; import android.view.View; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; import com.baidu.android.pushservice.CustomPushNotificationBuilder; import com.baidu.android.pushservice.PushConstants; import com.baidu.android.pushservice.PushManager; /* *云推送Demo主Activity。 *代码中,注释以Push标注开头的,表示接下来的代码块是Push接口调用示例 */ public class PushDemoActivity extends Activity implements View.OnClickListener{ private static final StringTAG=PushDemoActivity. class .getSimpleName(); RelativeLayoutmainLayout= null ; int akBtnId= 0 ; int initBtnId= 0 ; int richBtnId= 0 ; int setTagBtnId= 0 ; int delTagBtnId= 0 ; int clearLogBtnId= 0 ; ButtoninitButton= null ; ButtoninitWithApiKey= null ; ButtondisplayRichMedia= null ; ButtonsetTags= null ; ButtondelTags= null ; ButtonclearLog= null ; TextViewlogText= null ; ScrollViewscrollView= null ; public static int initialCnt= 0 ; private boolean isLogin= false ; @Override public void onCreate(BundlesavedInstanceState){ super .onCreate(savedInstanceState); Utils.logStringCache=Utils.getLogText(getApplicationContext()); Resourcesresource= this .getResources(); StringpkgName= this .getPackageName(); setContentView(resource.getIdentifier( "main" , "layout" ,pkgName)); akBtnId=resource.getIdentifier( "btn_initAK" , "id" ,pkgName); initBtnId=resource.getIdentifier( "btn_init" , "id" ,pkgName); richBtnId=resource.getIdentifier( "btn_rich" , "id" ,pkgName); setTagBtnId=resource.getIdentifier( "btn_setTags" , "id" ,pkgName); delTagBtnId=resource.getIdentifier( "btn_delTags" , "id" ,pkgName); clearLogBtnId=resource.getIdentifier( "btn_clear_log" , "id" ,pkgName); initWithApiKey=(Button)findViewById(akBtnId); initButton=(Button)findViewById(initBtnId); displayRichMedia=(Button)findViewById(richBtnId); setTags=(Button)findViewById(setTagBtnId); delTags=(Button)findViewById(delTagBtnId); clearLog=(Button)findViewById(clearLogBtnId); logText=(TextView)findViewById(resource.getIdentifier( "text_log" , "id" ,pkgName)); scrollView=(ScrollView)findViewById(resource.getIdentifier( "stroll_text" , "id" ,pkgName)); initWithApiKey.setOnClickListener( this ); initButton.setOnClickListener( this ); setTags.setOnClickListener( this ); delTags.setOnClickListener( this ); displayRichMedia.setOnClickListener( this ); clearLog.setOnClickListener( this ); //Push:以apikey的方式登录,一般放在主Activity的onCreate中。 //这里把apikey存放于manifest文件中,只是一种存放方式, //您可以用自定义常量等其它方式实现,来替换参数中的Utils.getMetaValue(PushDemoActivity.this, //"api_key") //通过sharepreference实现的绑定标志开关,如果已经成功绑定,就取消这次绑定 if (!Utils.hasBind(getApplicationContext())){ PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, Utils.getMetaValue(PushDemoActivity. this , "api_key" )); //Push:如果想基于地理位置推送,可以打开支持地理位置的推送的开关 //PushManager.enableLbs(getApplicationContext()); } //Push:设置自定义的通知样式,具体API介绍见用户手册,如果想使用系统默认的可以不加这段代码 //请在通知推送界面中,高级设置->通知栏样式->自定义样式,选中并且填写值:1, //与下方代码中PushManager.setNotificationBuilder(this,1,cBuilder)中的第二个参数对应 CustomPushNotificationBuildercBuilder= new CustomPushNotificationBuilder( getApplicationContext(),resource.getIdentifier( "notification_custom_builder" , "layout" ,pkgName), resource.getIdentifier( "notification_icon" , "id" ,pkgName), resource.getIdentifier( "notification_title" , "id" ,pkgName), resource.getIdentifier( "notification_text" , "id" ,pkgName)); cBuilder.setNotificationFlags(Notification.FLAG_AUTO_CANCEL); cBuilder.setNotificationDefaults(Notification.DEFAULT_SOUND |Notification.DEFAULT_VIBRATE); cBuilder.setStatusbarIcon( this .getApplicationInfo().icon); cBuilder.setLayoutDrawable(resource.getIdentifier( "simple_notification_icon" , "drawable" ,pkgName)); PushManager.setNotificationBuilder( this , 1 ,cBuilder); } @Override public void onClick(Viewv){ if (v.getId()==akBtnId){ initWithApiKey(); } else if (v.getId()==initBtnId){ initWithBaiduAccount(); } else if (v.getId()==richBtnId){ openRichMediaList(); } else if (v.getId()==setTagBtnId){ setTags(); } else if (v.getId()==delTagBtnId){ deleteTags(); } else if (v.getId()==clearLogBtnId){ Utils.logStringCache= "" ; Utils.setLogText(getApplicationContext(),Utils.logStringCache); updateDisplay(); } else { } } //打开富媒体列表界面 private void openRichMediaList(){ //Push:打开富媒体消息列表 IntentsendIntent= new Intent(); sendIntent.setClassName(getBaseContext(), "com.baidu.android.pushservice.richmedia.MediaListActivity" ); sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PushDemoActivity. this .startActivity(sendIntent); } //删除tag操作 private void deleteTags(){ LinearLayoutlayout= new LinearLayout(PushDemoActivity. this ); layout.setOrientation(LinearLayout.VERTICAL); final EditTexttextviewGid= new EditText(PushDemoActivity. this ); textviewGid.setHint( "请输入多个标签,以英文逗号隔开" ); layout.addView(textviewGid); AlertDialog.Builderbuilder= new AlertDialog.Builder( PushDemoActivity. this ); builder.setView(layout); builder.setPositiveButton( "删除标签" , new DialogInterface.OnClickListener(){ public void onClick(DialogInterfacedialog, int which){ //Push:删除tag调用方式 List<String>tags=Utils.getTagsList(textviewGid .getText().toString()); PushManager.delTags(getApplicationContext(),tags); } }); builder.show(); } //设置标签,以英文逗号隔开 private void setTags(){ LinearLayoutlayout= new LinearLayout(PushDemoActivity. this ); layout.setOrientation(LinearLayout.VERTICAL); final EditTexttextviewGid= new EditText(PushDemoActivity. this ); textviewGid.setHint( "请输入多个标签,以英文逗号隔开" ); layout.addView(textviewGid); AlertDialog.Builderbuilder= new AlertDialog.Builder( PushDemoActivity. this ); builder.setView(layout); builder.setPositiveButton( "设置标签" , new DialogInterface.OnClickListener(){ public void onClick(DialogInterfacedialog, int which){ //Push:设置tag调用方式 List<String>tags=Utils.getTagsList(textviewGid .getText().toString()); PushManager.setTags(getApplicationContext(),tags); } }); builder.show(); } //以apikey的方式绑定 private void initWithApiKey(){ //Push:无账号初始化,用apikey绑定 PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, Utils.getMetaValue(PushDemoActivity. this , "api_key" )); } //以百度账号登陆,获取accesstoken来绑定 private void initWithBaiduAccount(){ if (isLogin){ //已登录则清除Cookie,accesstoken,设置登录按钮 CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); CookieSyncManager.getInstance().sync(); isLogin= false ; initButton.setText( "登陆百度账号初始化Channel" ); } //跳转到百度账号登录的activity Intentintent= new Intent(PushDemoActivity. this ,LoginActivity. class ); startActivity(intent); } @Override public void onStart(){ super .onStart(); } @Override public void onResume(){ super .onResume(); Log.d(TAG, "onResume" ); updateDisplay(); } @Override protected void onNewIntent(Intentintent){ Stringaction=intent.getAction(); if (Utils.ACTION_LOGIN.equals(action)){ //Push:百度账号初始化,用accesstoken绑定 StringaccessToken=intent .getStringExtra(Utils.EXTRA_ACCESS_TOKEN); PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_ACCESS_TOKEN,accessToken); isLogin= true ; initButton.setText( "更换百度账号" ); } updateDisplay(); } @Override public void onStop(){ super .onStop(); } @Override public void onDestroy(){ Utils.setLogText(getApplicationContext(),Utils.logStringCache); super .onDestroy(); } //更新界面显示内容 private void updateDisplay(){ Log.d(TAG, "updateDisplay,logText:" +logText+ "cache:" +Utils.logStringCache); if (logText!= null ){ logText.setText(Utils.logStringCache); } if (scrollView!= null ){ scrollView.fullScroll(ScrollView.FOCUS_DOWN); } } } 注意:这句话才是关键。 PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, Utils.getMetaValue(PushDemoActivity.this, "api_key")); 下面分别是打开另一个activity和打开指定的网页的效果图: 附图: 附件:http://down.51cto.com/data/2364801 本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1544813,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

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

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文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

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