极光推送sdk使用
2018-05-21 08:56
483 查看
创建应用
进入极光控制台后,点击“创建应用”按钮,进入创建应用的界面。 填上你的应用程序的名称以及应用包名这二项就可以了, 最后点击最下方的 “创建我的应用”按钮,创建应用完毕。
![](http://upload-images.jianshu.io/upload_images/11122608-51f6bb2914a499d2.png)
![](http://upload-images.jianshu.io/upload_images/11122608-0870695205818ef8.png)
![](http://upload-images.jianshu.io/upload_images/11122608-9c92e95c2e4b828d.png)
![](http://upload-images.jianshu.io/upload_images/11122608-e7a48adbbf5c4a4d.png)
jcenter 自动集成步骤
- 确认android studio的 Project 根目录的主 gradle 中配置了jcenter支持(基本默认支持)
buildscript { repositories { jcenter() } ...... } allprojets { repositories { jcenter() } }
- 在 module 的 gradle 中添加依赖
android { ...... defaultConfig { applicationId "com.xxx.xxx" //JPush上注册的包名. ...... ndk { //选择要添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64' } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "你的appkey", //JPush上注册的包名对应的appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] ...... } ...... } dependencies { ...... compile 'cn.jiguang.sdk:jpush:3.1.1' // 此处以JPush 3.1.1 版本为例。 compile 'cn.jiguang.sdk:jcore:1.1.9' // 此处以JCore 1.1.9 版本为例。 ...... }
- AndroidManifest替换变量(在本地的 AndroidManifest 中定义同名的组件并配置想要的属性,然后用 xmlns:tools 来控制本地组件覆盖 jcenter 上的组件,一般替换receiver,记得修改category属性值)
<application ...> <!-- 替换原生极光推送接收器 --> <receiver android:name=".jpush.MyReceiver" android:enabled="true" android:exported="false" tools:node="replace"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!-- Required 用户注册SDK的intent --> <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.xxx.xxx" /> <!--JPush上注册的包名 --> </intent-filter> </receiver> </application>
调试以及使用
- 在Application的onCreate()初始化Sdk
@Override public void onCreate() { super.onCreate(); JPushInterface.setDebugMode(true); JPushInterface.init(this); }
- MyReceiver对推送进行处理
public class MyReceiver extends BroadcastReceiver { private static final String TAG = "JIGUANG"; public static String regId; @Override public void onReceive(Context context, Intent intent) { try { Bundle bundle = intent.getExtras(); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId); //send the Registration Id to your server... } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息(内容为): " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); // 自定义消息不是通知,默认不会被SDK展示到通知栏上,极光推送仅负责透传给SDK。其内容和展示形式完全由开发者自己定义。 // 自定义消息主要用于应用的内部业务逻辑和特殊展示需求 } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "[MyReceiver] 接收到推送下来的通知"); String extra_json = bundle.getString(JPushInterface.EXTRA_EXTRA); if (!TextUtils.isEmpty(extra_json)) Log.d(TAG, "[MyReceiver] 接收到推送下来的通知附加字段" + extra_json); // 可以利用附加字段来区别Notication,指定不同的动作,extra_json是个json字符串 // 通知(Notification),指在手机的通知栏(状态栏)上会显示的一条通知信息 } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { Log.d(TAG, "[MyReceiver] 用户点击打开了通知"); // 在这里根据 JPushInterface.EXTRA_EXTRA(附加字段) 的内容处理代码, // 比如打开新的Activity, 打开一个网页等.. } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); Log.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); } else { Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); } } catch (Exception e) { e.printStackTrace(); } } }
- 利用别名精准推送
// 一般登录之后调用此方法设置别名 // sequence 用来标识一次操作的唯一性(退出登录时根据此参数删除别名) // alias 设置有效的别名 // 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。限制:alias 命名长度限制为 40 字节。 JPushInterface.setAlias(context, int sequence, String alias); // 退出登录删除别名 JPushInterface.deleteAlias(Context context,int sequence);
相关文章推荐
- iOS极光推送SDK的使用流程
- iOS极光推送SDK的使用流程
- iOS开发-极光推送SDK使用笔记
- iOS开发(第三方使用)——极光推送SDK接入
- PhoneGap与极光SDK整合,实现消息推送
- 极光推送使用实例(二) Android客户端
- 使用android studio集成极光推送
- Android 使用极光推送消息详细介绍之自定义消息
- IOS开发使用极光平台进行远程推送
- 使用第三方推送平台 极光推送
- cordova极光推送插件使用
- Android Study 之 极光推送使用心得以及记录
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
- 学习使用Android极光消息推送
- 百度推送SDK之使用总结(五)
- 极光推送集成安卓sdk
- 【转载】极光推送 使用实例 (一)服务端
- TP5中使用极光推送3.5.12
- Android 使用极光推送自定义消息打造个性的消息推送效果
- 一个使用http2的苹果推送python版SDK