GCM(4)GoogleCloudMessaging
1. Reading the documents
The registration ID identifies the device and application, and also determines which 3rd-party application servers are allowed to send messages to this application instance.
A sender ID is a project number you acquire from the API console. A sender ID is used to identify a 3rd-party application server that is permitted to send messages.
String SENDER_ID = “”;
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String registrationId = gcm.register(SENDER_ID);
<uses-permissionandroid:name="com.google.android.c2dm.permission.RECEIVE"/>
<receiverandroid:name=".MyReceiver"android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND"]]>
<intent-filter>
<actionandroid:name="com.google.android.c2dm.intent.RECEIVE"/>
<categoryandroid:name="YOUR_PACKAGE_NAME"/>
</intent-filter>
</receiver>
When we receive the message from server
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)){
//It’s an error.
}else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)){
}else if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)){
//regular GCM message.
}
2. Start from My Old GCM Example
Make sure I have this directory with google play services installed.
/opt/android-sdk/extras/google/google_play_services
Add Support lib to eclipse
Select the project —> Android Tool ——> Add Support Library
Add Support lib to android studio
Add this lib to the maven pom.xml file
<dependency><groupId>com.google.android</groupId><artifactId>support-v4</artifactId><version>r7</version>
</dependency>
Give up to using maven, I should know about gradle.
3. Install Gradle and Setup
Download and get the latest version
http://downloads.gradle.org/distributions/gradle-1.10-all.zip
Unzip and copy to working directory
>pwd
/Users/carl/tool/gradle-1.10
Soft link it to my /opt directory
>sudo ln -s /Users/carl/tool/gradle-1.10 /opt/gradle-1.10
>sudo ln -s /opt/gradle-1.10 /opt/gradle
>sudo vi ~/.profile
export GRADLE_HOME=/opt/gradle
export PATH=${GRADLE_HOME}/bin:$PATH
>. ~/.profile
Verify the Installation
>gradle -v
------------------------------------------------------------ Gradle 1.10
------------------------------------------------------------
Some error there as follow, when I run command gradle build under my android project:
* What went wrong: A problem occurred evaluating root project 'EasyRestClientAndroid'.
> Could not create plugin of type 'AppPlugin'.
I switch my gradle to 1.9
>gradle tasks
>gradle tasks —all
Error Message
Execution failed for task ':packageRelease'. > class org.bouncycastle.asn1.ASN1Primitive overrides final method equals
Solution:
Get rid of bcprov-jdk16-1.46.jar
4. Go on with the Example
The latest example is in project EasyAndroidGCM.
Tips for Gradle
Install the app on the device
>gradle installDebug
Tips for Android Studio
Show Line Number
Android Studio ——> Preferences——> Editor ——> Appearance ———> Show line numbers
Keymap
Android Studio ——> Preferences ——> Keymap ——> keymaps ——> Eclipse(Mac OS X)
Android Studio —> Preferences ———> Editor —> Auto Import ——> Add unambiguous imports on the fly
References:
http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html
http://developer.android.com/reference/com/google/android/gcm/GCMBaseIntentService.html#getSenderIds(android.content.Context
GCM 1~3
http://sillycat.iteye.com/blog/1769191
http://sillycat.iteye.com/blog/1769196
http://sillycat.iteye.com/blog/1838432
Latest Sample
https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client%2Fsrc%2Fcom%2Fgoogle%2Fandroid%2Fgcm%2Fdemo%2Fapp%253Fstate%253Dclosed
http://www.appsrox.com/android/tutorials/instachat/3/
http://tausiq.wordpress.com/2013/09/24/android-push-notification-cloud-to-device-messaging/
gradle
http://sillycat.iteye.com/blog/1074642
http://tools.android.com/tech-docs/new-build-system/user-guide
http://spring.io/guides/gs/gradle-android/
https://github.com/spring-guides/gs-gradle-android
sample
https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf
- 浏览: 2492657 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1231ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 598ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1623ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 944Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 546Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 685ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 787Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 891Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1300Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 732Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1011Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1061Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 733Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 694Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 434Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 654Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1051Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 1984Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 854IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1279IOS7 App Development Essentials ...
相关推荐
gcm - Google Cloud Messaging的Go库
AES GCM算法,可以编译通过执行,没看懂
GCM加密的源码,实现AES—GCM加密模式
aes gcm siv 256 算法加密解密源程序,GitHub源码
AesTestTool为加密软件,支持GCM 和 ECB两种模式 128bit秘钥 GCM算法是一个C++工程,“C++gcm算法工程”目录里面有源码 加密软件是用C#写的,所以把C++工程编译成了dll文件,由C#调用 “软件工程目录”文件夹是...
AES GCM 128 bit加密算法工程源码,C++语言实现,希望能够帮助到大家
主要是aes-gcm算法实现的code,详细描述gcm算法的各部分实现过程
在工作中会经常遇到密码加密,URL传参要进行加密,在此我参照一个例子将用java实现的AES加解密程序用实例写出。JS实现AES-GCM加密,java实现AES-GCM解密
使用intel的simd方式,调用avx2指令,运算速度较快。
aes128-gcm 电表相关加密算法源码
gcm python算法 包含aes128 狂欢,
google在今年六月份发布了新的推送机制GCM,取代C2DM.
高版本AES-GCM模式加密的Shiro漏洞利用1
GCM加密模式加密模式
详细介绍了GCM开发步骤与注意事项等,对初步接触GCM的童鞋蛮有作用的
包含android推送服务GCM发开源代码,非jar包内容
加密认证联合模式的源代码,加密认证的加密算法均采用AES加密。包含了EAX GCM CCM三种联合加密认证的算法资源文件。
这个文档是在官方网站上下载的,讲述很详尽,还有很多加密数据的例子,方便验证自己的程序,不过是英文的 这个文档是在官方网站上下载的,讲述很详尽,还有很多加密数据的例子,方便验证自己的程序,不过是英文的
AES-GCM是当前最新的AES算法的一种加密和认证的模式,利用AES进行数据加密和解密,利用GHASH进行身份验证,更加安全可靠。
做国外电表DLMS加解密必用的算法,费劲我几个月的整理修改,总算把这GCM-AES-128的加解密算法和密钥传输的包裹算法弄好。算是商业机密吧,呵呵!据说有厂家为数据传输加解密前前后后搞了2年。 压缩包里有三个代码...