android126 zhihuibeijing 极光推送
https://www.jpush.cn/
张三把消息发送给自己的服务器,自己的服务器将消息发送给极光推送,然后极光推送将消息发送给妹子。
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.pushdemo"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /> <permission
android:name="com.itheima.pushdemo.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" /> <!-- Required 一些系统要求的权限,如访问网络等 -->
<uses-permission android:name="com.itheima.pushdemo.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <!-- Optional for location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name=".MyApplication"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.itheima.pushdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- Required SDK核心功能 -->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="com.itheima.pushdemo" />
</intent-filter>
</activity>
<!-- Required SDK核心功能 -->
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false" >
</service> <!-- Required SDK 核心功能 -->
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER" />
<action android:name="cn.jpush.android.intent.REPORT" />
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service> <!-- Required SDK核心功能 -->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true" >
<intent-filter android:priority="1000" >
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!-- Required 显示通知栏 -->
<category android:name="com.itheima.pushdemo" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" />
</intent-filter>
</receiver> <!-- Required SDK核心功能 -->
<receiver android:name="cn.jpush.android.service.AlarmReceiver" /> <!-- User defined. 用户自定义的广播接收器 -->
<receiver
android:name=".PushReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" /> <!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.UNREGISTRATION" />
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.CONNECTION" /> <!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category android:name="com.itheima.pushdemo" />
</intent-filter>
</receiver> <!-- Required . Enable it you can get statistics data with channel -->
<meta-data
android:name="JPUSH_CHANNEL"
android:value="developer-default" />
<meta-data
android:name="JPUSH_APPKEY"
android:value="1bf870ba4e7e4020d7943d33" /> <!-- </>值来自开发者平台取得的AppKey -->
</application> </manifest>
package com.itheima.pushdemo; import android.app.Activity;
import android.os.Bundle;
import android.view.Menu; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyApplication application = (MyApplication) getApplication();
application.doSomething();
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
package com.itheima.pushdemo; import android.app.Application;
import cn.jpush.android.api.JPushInterface; /**
* 自定义application,应用自己会有一个Application,这里继承了就用自己的Application不用系统的Application。
* 这个Application是单例的。
*/
public class MyApplication extends Application { @Override
public void onCreate() {
super.onCreate();
System.out.println("应用创建啦...."); JPushInterface.setDebugMode(true);
JPushInterface.init(this);
} public void doSomething() {
System.out.println("do something...");
} }
package com.itheima.pushdemo; import org.json.JSONException;
import org.json.JSONObject; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import cn.jpush.android.api.JPushInterface; public class PushReceiver extends BroadcastReceiver { private static final String TAG = "PushReceiver"; @Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Log.d(TAG, "onReceive - " + intent.getAction()); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent
.getAction())) {
System.out.println("收到了自定义消息。消息内容是:"
+ bundle.getString(JPushInterface.EXTRA_MESSAGE));
// 自定义消息不会展示在通知栏,完全要开发者写代码去处理
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent
.getAction())) {//手机收到了通知时调用
System.out.println("收到了通知");
// 在这里可以做些统计,或者做些其他工作
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent
.getAction())) {//用户点击手机打开了通知时调用
System.out.println("用户点击打开了通知");
// 在这里可以自己写代码去定义用户点击后的行为
String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);
System.out.println("附加信息:" + extra); try {
JSONObject jo = new JSONObject(extra);
String url = jo.getString("url"); System.out.println("url:" + url);
// 跳浏览器加载网页
} catch (JSONException e) {
e.printStackTrace();
} }
} }
## 极光推送 ## 所有需要客户端被动接收信息的功能模块,都可以用推送实现 ## 推送原理 ## - xmpp 是一种基于TCP/IP的协议, 这种协议更适合消息发送.
- socket 套接字, 发送和接收网络请求
- 长连接 keep-alive, 服务器基于长连接找到设备,发送消息(客户端可以通过ip找到服务器,但是客户端的ip会变,所以要长连接保证服务器可以找到客户端)
- 心跳包(客户端可能会有短暂的断网) , 客户端会定时(30秒一次)向服务器发送一段极短的数据(几个字节),作为心跳包, 服务器定时收到心跳,证明客户端活着,才会发消息.否则将消息保存起来,等客户端活了之后(重新连接),重新发送.
> 客户端轮询(客户端定时主动拉取数据,客户端定时器去请求服务端接口), 浪费流量, 浪费性能
> 谷歌推送服务(不能用,被墙了)
android126 zhihuibeijing 极光推送的更多相关文章
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...
- 极光推送-适配 iOS10
//************************ iOS10 适配 **************************// //************************ 11/02/20 ...
- iOS推送(利用极光推送)
本文主要是基于极光推送的SDK封装的一个快速集成极光推送的类的封装(不喜勿喷) (1)首先说一下推送的一些原理: Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指 ...
- 极光推送JPush的快速集成
首先到极光推送的官网上创建一个应用,填写对应的应用名和包名. 创建好之后下载Demo 提取Sdk里面的图片和xml等资源文件放自己项目的相应位置,然后要注意的是.so文件的放置位置: 在main目录下 ...
- APP的消息推送(极光推送)
APP的消息推送,使用的第三方平台是极光推送 简单案例(以Thinkphp为例): 1.下载下载PHPSDK 2.把PHPSDK目录下的jpush-api-php-client-3.5.1\src\J ...
- 【原】iOS学习之极光推送
一.极光推送工程端 1.下载SDK 极光推送是一个推送消息的第三方,SDK下载:https://www.jpush.cn/common/products 集成压缩包内容:包名为JPush-iOS-SD ...
- 极光推送Jpush(v3)服务端PHP版本的api脚本类
原文地址:http://www.dodobook.net/php/780 关于极光推送的上一篇文章已经说明了,此处就不多说了.使用v3版本的原因是v2使用到2014年年底就停止了.点击查看上一篇的地址 ...
- tp的极光推送demo
原文地址:http://blog.csdn.net/zhihua_w/article/details/52197611 极光推送(JPush)是独立的第三方云推送平台,致力于为全球移动应用开发者提供专 ...
随机推荐
- 8.8-8.10 usaco
summary:44 没救了...整天刷水迟早药丸! ❤bzoj3892: 区间dp.我原来的思路是dp[i][j]表示前i个数跳过了j次,那么转移可以前k个数转移了j-1次,枚举k就好了,但是这样是 ...
- NOI2002robot
这题又是纯数论题…… 独立数就是欧拉函数,政客和军人的含义已经说的很清楚了,学者是最多的…… 首先,如果我们知道了政客和军人的答案,那就只要用n的所有因子的欧拉函数值减去这两个值,然后取模就行了. 但 ...
- 【 随笔 】 D3 难吗?
有不少朋友说学 D3 挺难的.为什么呢?想写一篇文章分析分析. 1. D3 出现的背景 D3.js 是 Github 上的一个开源项目,用于数据可视化.作者是 Mike Bostock,纽约时报的工程 ...
- Query Profiler 和Explain 用法详解
一.Query Profiler MySQL 的Query Profiler 是一个使用非常方便的Query 诊断分析工具,通过该工具可以获取一条Query 在整个执行过程中多种资源的消耗情况,如C ...
- TCP 滑动窗口的简介
TCP 滑动窗口的简介 POSTED BY ADMIN ON AUG 1, 2012 IN FLOWS34ARTICLES | 0 COMMENTS TCP的滑动窗口主要有两个作用,一是提供TCP的可 ...
- 50道经典的JAVA编程题(目录)
这份题从2013做到2014啊...哈哈,整理个目录吧.为了好查阅,也为了监督自己好好的去做完这50道题.当然,有些题实在做得没意思就跳过了,或者自己改题了.题目来源于:http://blog.sin ...
- tomcat登陆WEB显示无权限问题&& tomcat无限循环启动问题
tomcat登陆WEB显示无权限问题 The user specified as a definer (”@’%') does not exist 原因分析 因为创建视图使用的是xff@%用户(目前已 ...
- Java之ByteArrayInputStream和ByteArrayOutputStream-操作字节数组的类
ByteArrayInputStream和ByteArrayOutputStream 源:内存中的字节数组 目的:内存中的字节数组 这两个流对象不涉及底层资源的调用,操作的都是内存中的数组,所以不需要 ...
- SQL2008-中不想插入从复记录
If not exists (SELECT ID FROM StuffAgitationYield where EMAgitation_ID=1 and YieldDateTime'2012-06-1 ...
- 转载 DNS查询流程简介
转载请注明出处:http://blog.csdn.net/luotuo44/article/details/45545059 DNS(domain name system),读者们或多或少都听过,就是 ...