- 浏览: 2578794 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
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
GCM(1)Get Start
1. Getting Started
Follow the document to create Google APIs Console project
The URL are as follow:
https://code.google.com/apis/console/
I click create project to create an API project and then rename it to easymessagepush.
Take a note of my project number ***
Enabling the GCM Service
Click on the Service tab menu and turn on the 'Google Cloud Messaging for Android'
Obtaining an API Key
Select the tab menu, 'API Access'
I just select the 3 one by one
Create new Server key
Create new Browser key
Create new Android key
I did not type in something, I want make them allowed for any app, any IP and any referer right now, maybe I will change that in the future.
Install the Helper Libraries
From the SDK Manager on eclipse, find the menu
Extras ---> Google Cloud Messaging for Android Library
Install this feature, it will create a GCM directory under my SDK ROOT/extras/google/
For me, that is /opt/android-sdk/extras/google
Everything will be in this directory /opt/android-sdk/extras/google/gcm
Writing the Android Application
Step1: Copy the gcm.jar file into our application classpath
find the gcm.jar from here gcm-client/dist
My project is managed by MAVEN, so I decide to add this in pom.xml
<dependency>
<groupId>com.google.android</groupId>
<artifactId>gcm</artifactId>
<version>1.0.2</version>
</dependency>
Step2: Make the following changes in the application's Android manifest
1. GCM requires Android 2.2 or later, make sure we have this kind of line in AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15"/>
2. Declare and use a custom permission so only this application can receive GCM message:
<permission android:name="com.sillycat.easyrestclientandroid.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="com.sillycat.easyrestclientandroid.permission.C2D_MESSAGE"/>
The package name com.sillycat.easyrestclientandroid should be the same as
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.sillycat.easyrestclientandroid" …snip…
3. Add the following permissions
<!-- App receives GCM messages. -->
<uses-permissionandroid:name="com.google.android.c2dm.permission.RECEIVE"/>
<!-- GCM connects to Google Services. -->
<uses-permissionandroid:name="android.permission.INTERNET"/>
<!-- GCM requires a Google account. -->
<uses-permissionandroid:name="android.permission.GET_ACCOUNTS"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permissionandroid:name="android.permission.WAKE_LOCK"/>
4. Add the following broadcast receiver
<application>
…snip...
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action
android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category
android:name="com.sillycat.easyrestclientandroid" />
</intent-filter>
</receiver>
…snip…
</application>
This broadcast receiver is responsible for handling the 2 intents that can be sent by GCM.
com.google.android.c2dm.intent.RECEIVE
com.google.android.c2dm.intent.REGISTRATION
These should be defined in the manifest(rather than programmatically) so that these intents can be received even if the application is not running.
5. Add the following intent service
<application>
…snip..
<service android:name=".GCMIntentService" />
…snip...
</application>
This intent service will be called by the GCMBroadcastReceiver.
Step 3: Write the GCMIntentService class
The detail of the project is in the sample EasyRestClientAndroid project.
Writing the Server-side Application
The detail is in project 4mymessage project.
References:
https://developer.android.com/google/gcm/gcm.html
https://developer.android.com/google/gcm/gs.html
1. Getting Started
Follow the document to create Google APIs Console project
The URL are as follow:
https://code.google.com/apis/console/
I click create project to create an API project and then rename it to easymessagepush.
Take a note of my project number ***
Enabling the GCM Service
Click on the Service tab menu and turn on the 'Google Cloud Messaging for Android'
Obtaining an API Key
Select the tab menu, 'API Access'
I just select the 3 one by one
Create new Server key
Create new Browser key
Create new Android key
I did not type in something, I want make them allowed for any app, any IP and any referer right now, maybe I will change that in the future.
Install the Helper Libraries
From the SDK Manager on eclipse, find the menu
Extras ---> Google Cloud Messaging for Android Library
Install this feature, it will create a GCM directory under my SDK ROOT/extras/google/
For me, that is /opt/android-sdk/extras/google
Everything will be in this directory /opt/android-sdk/extras/google/gcm
Writing the Android Application
Step1: Copy the gcm.jar file into our application classpath
find the gcm.jar from here gcm-client/dist
My project is managed by MAVEN, so I decide to add this in pom.xml
<dependency>
<groupId>com.google.android</groupId>
<artifactId>gcm</artifactId>
<version>1.0.2</version>
</dependency>
Step2: Make the following changes in the application's Android manifest
1. GCM requires Android 2.2 or later, make sure we have this kind of line in AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15"/>
2. Declare and use a custom permission so only this application can receive GCM message:
<permission android:name="com.sillycat.easyrestclientandroid.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="com.sillycat.easyrestclientandroid.permission.C2D_MESSAGE"/>
The package name com.sillycat.easyrestclientandroid should be the same as
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.sillycat.easyrestclientandroid" …snip…
3. Add the following permissions
<!-- App receives GCM messages. -->
<uses-permissionandroid:name="com.google.android.c2dm.permission.RECEIVE"/>
<!-- GCM connects to Google Services. -->
<uses-permissionandroid:name="android.permission.INTERNET"/>
<!-- GCM requires a Google account. -->
<uses-permissionandroid:name="android.permission.GET_ACCOUNTS"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permissionandroid:name="android.permission.WAKE_LOCK"/>
4. Add the following broadcast receiver
<application>
…snip...
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action
android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category
android:name="com.sillycat.easyrestclientandroid" />
</intent-filter>
</receiver>
…snip…
</application>
This broadcast receiver is responsible for handling the 2 intents that can be sent by GCM.
com.google.android.c2dm.intent.RECEIVE
com.google.android.c2dm.intent.REGISTRATION
These should be defined in the manifest(rather than programmatically) so that these intents can be received even if the application is not running.
5. Add the following intent service
<application>
…snip..
<service android:name=".GCMIntentService" />
…snip...
</application>
This intent service will be called by the GCMBroadcastReceiver.
Step 3: Write the GCMIntentService class
The detail of the project is in the sample EasyRestClientAndroid project.
Writing the Server-side Application
The detail is in project 4mymessage project.
References:
https://developer.android.com/google/gcm/gcm.html
https://developer.android.com/google/gcm/gs.html
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1276ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 650ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1678ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 994Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 598Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 741ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 837Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 922Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1358Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 777Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1074Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1121Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 787Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 742Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 504Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 707Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1108Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 2069Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 910IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1363IOS7 App Development Essentials ...
相关推荐
Modes come with a start, encrypt/decrypt and set/get IV interfaces. Mode supported. ECB CBC OFB CFB CTR 单向 Hash 函数 支持的hash方式. MD2 MD4 MD5 (较为常用) SHA-1 SHA-224/256/384/512...
To start with, we will discuss the details of the Android process model and the Java low-level concurrent framework, delivered by the Android SDK. Next, we will discuss the creation of IntentServices...
To start with, we will discuss the details of the Android process model and the Java low-level concurrent framework, delivered by the Android SDK. Next, we will discuss the creation of IntentServices...
2. GCM/FCM的唤醒机制:Google提供的云消息推送(GCM/FCM)可以在设备休眠状态下唤醒应用,用于执行后台任务。 3. JobScheduler:Android API 14以上可以使用JobScheduler来安排后台任务,系统会在满足条件时自动...
Modes come with a start, encrypt/decrypt and set/get IV interfaces. Mode supported. ECB CBC OFB CFB CTR IEEE LRW mode F8 Chaining Mode One-Way Hash Functions Hashes come with init, process, ...
如果需要重启Nginx服务,可以使用`service nginx stop`、`service nginx start`或`service nginx restart`命令。 最后,确保服务器的安全组设置允许80和443端口的入站流量。在阿里云ECS管理后台的相应安全组规则中...