极光注册就不说了,首先配置App的build.grandle

在defaultConfig里粘贴一下内容appkey为我在极光注册之后的Appkey

然后配置AndroidManifest  把下面这些信息放在application里面

<!--极光的--><!-- Required SDK 核心功能 --><!-- 可配置android:process参数将PushService放在其他进程中 --><serviceandroid: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><!-- since 3.0.9 Required SDK 核心功能 --><providerandroid:authorities="com.hemai.rider.DataProvider"android:name="cn.jpush.android.service.DataProvider"android:exported="true"/><!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 --><!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 --><serviceandroid:name="cn.jpush.android.service.DaemonService"android:enabled="true"android:exported="true"><intent-filter><action android:name="cn.jpush.android.intent.DaemonService" /><category android:name="com.hemai.rider" /></intent-filter></service><!-- Required SDK核心功能 --><receiverandroid:name="cn.jpush.android.service.PushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /><category android:name="com.hemai.rider" /></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核心功能 --><activityandroid:name="cn.jpush.android.ui.PushActivity"android:configChanges="orientation|keyboardHidden"android:exported="false"android:theme="@android:style/Theme.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.ui.PushActivity" /><category android:name="android.intent.category.DEFAULT" /><category android:name="com.hemai.rider" /></intent-filter></activity><!-- SDK核心功能 --><activityandroid:name="cn.jpush.android.ui.PopWinActivity"android:configChanges="orientation|keyboardHidden"android:exported="false"android:theme="@style/MyDialogStyle"><intent-filter><category android:name="android.intent.category.DEFAULT" /><category android:name="com.hemai.rider" /></intent-filter></activity><!-- Required SDK核心功能 --><serviceandroid:name="cn.jpush.android.service.DownloadService"android:enabled="true"android:exported="false" /><!-- Required SDK核心功能 --><receiver android:name="cn.jpush.android.service.AlarmReceiver" /><!-- Required since 3.0.7 --><!-- 新的tag/alias接口结果返回需要开发者配置一个自定的广播 --><!-- 该广播需要继承JPush提供的JPushMessageReceiver类, 并如下新增一个 Intent-Filter --><receiverandroid:name="com.hemai.jpush.MyJPushMessageReceiver"android:enabled="true"><intent-filter><action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /><category android:name="com.hemai.rider" /></intent-filter></receiver><!-- User defined. 用户自定义的广播接收器 --><receiverandroid:name="com.hemai.jpush.MyReceiver"android:enabled="true"><intent-filter><!-- Required 用户注册SDK的intent --><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 用户打开自定义通知栏的intent --><action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /><!-- 接收网络变化 连接/断开 since 1.6.3 --><action android:name="cn.jpush.android.intent.CONNECTION" /><category android:name="com.hemai.rider" /></intent-filter></receiver>

然后在项目的根目录创建一个jpush的包在里面创建五个类

首先来说MyJpushMessageReceiver

/*** 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)* */
public class MyJPushMessageReceiver extends JPushMessageReceiver {@Overridepublic void onTagOperatorResult(Context context,JPushMessage jPushMessage) {TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);super.onTagOperatorResult(context, jPushMessage);}@Overridepublic void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);super.onCheckTagOperatorResult(context, jPushMessage);}@Overridepublic void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);super.onAliasOperatorResult(context, jPushMessage);}
}
然后是自定义的接收器Myreciever
*** 自定义接收器* <p>* 如果不定义这个 Receiver,则:* 1) 默认用户会打开主界面* 2) 接收不到自定义消息*/
public class MyReceiver extends BroadcastReceiver {private static final String TAG = "tag";@Overridepublic void onReceive(Context context, Intent intent) {try {Bundle bundle = intent.getExtras();Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);Logger.e(TAG, "[MyReceiver] 接收Registration Id : " + regId);} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));//processCustomMessage(context, bundle);} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);//bundle.get(JPushInterface.EXTRA_ALERT);推送内容Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);//获取到的推送的通知类型String str_Test = bundle.getString(JPushInterface.EXTRA_ALERT);Log.e("tag", "测试:" + str_Test);//在这里自定义通知声音processCustomMessage(context,bundle);//这里通过EventBus来想我需要更新数据的界面发送更新通知EventBus.getDefault().postSticky(new MessageEvent(str_Test));} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {Logger.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);Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);} else {Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());}} catch (Exception e) {}}// 打印所有的 intent extra 数据private static String printBundle(Bundle bundle) {StringBuilder sb = new StringBuilder();for (String key : bundle.keySet()) {if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));} else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));} else if (key.equals(JPushInterface.EXTRA_EXTRA)) {if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {Logger.i(TAG, "This message has no Extra data");continue;}try {JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));Iterator<String> it = json.keys();while (it.hasNext()) {String myKey = it.next();sb.append("\nkey:" + key + ", value: [" +myKey + " - " + json.optString(myKey) + "]");}} catch (JSONException e) {Logger.e(TAG, "Get message extra JSON error!");}} else {sb.append("\nkey:" + key + ", value:" + bundle.getString(key));}}return sb.toString();}/***  自定义推送的声音* @param context* @param bundle*/private void processCustomMessage(Context context, Bundle bundle) {NotificationCompat.Builder notification = new NotificationCompat.Builder(context);//这一步必须要有而且setSmallIcon也必须要,没有就会设置自定义声音不成功notification.setAutoCancel(true).setSmallIcon(R.mipmap.logo1);String alert = bundle.getString(JPushInterface.EXTRA_ALERT);if (alert!=null&&!alert.equals("")){notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.notification));}//最后刷新notification是必须的NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);notificationManager.notify(1,notification.build());}
另外三个ExampleUtil, Logger,TagAliasOperatorHelper为辅助类极光官方提供。
做完这些之后推送还是不能推送到你的手机,因为你没有把你的设备号给到后台,所以登陆的是要做处理
获取本地设备号然后请求极光提供的方法setJupshAlisa方法
 //获取手机设备号
TelephonyManager tm = (TelephonyManager) LoginActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = tm.getDeviceId();
SetJuPshAlias(deviceId);
 /*** 向极光绑定别名(后台必须要根据注册在极光的别名进行个推)*//*** 设置、覆盖签名(可以自定逻辑判断(如果设置过了就不需要在设置)* <p>* String Myalias:别名(和后台商定(例如使用Uid))*/public static final int ACTION_SET = 2;public void SetJuPshAlias(String Myalias) {TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();tagAliasBean.isAliasAction = true;tagAliasBean.action = ACTION_SET;tagAliasBean.alias = Myalias;//TagAliasOperatorHelper.getInstance().handleAction(getActivity(),sequence,tagAliasBean);JPushInterface.setAlias(this, sequence, tagAliasBean.alias);regId = JPushInterface.getRegistrationID(this);Log.e("tag", "极光设备号:"+regId);if (regId!=null&&!regId.equals("")){btnlogin.setOnClickListener(this);}else {showToast("设备号为空,请重新登录");userName.setText("");passward.setText("");}}
得到极光返回的设备号之后就可以登录啦

第一篇博客:极光推送以及自定义推送声音相关推荐

  1. C博客作业00--我的第一篇博客

    这个作业属于哪个班级 C语言–网络2011/2012 这个作业的地址 C博客作业00–我的第一篇博客 这个作业的目标 学习Makdown语法,对本专业及C语言课程有个简单了解,记录自学慕课视频的笔记. ...

  2. 2023年的第一篇博客

    这是2023年的第一篇博客,想写些技术以外的东西,顺便做下博客1.2月份的内容预告,2月底之前会更新完FPGA 20个例程篇的最后两个例程即OV7725摄像头采集送显HDMI. RS232 USB L ...

  3. 蒟蒻的第一篇博客CF1041C Coffee Break(二分+贪心+set)

    CF1041C Coffee Break(二分+贪心+set) 描述 Recently Monocarp got a job. His working day lasts exactly mm min ...

  4. 这是我的第一篇博客!

    这是我的第一篇博客~ 这个博客账号将会由一个技术菜鸡来总结一些我学习的东西,也许会总结的乱七八糟,也许会错误频频,甚至看不懂在写个什么(emmm有点过分)...但是无所谓啦,目的只是希望以后能向各路大 ...

  5. 点滴篇(一) 第一篇 博客

    我的第一篇博客~~~ 这个博客就为技术贴吧,以后我会分享自己在学习中的点点滴滴

  6. 第一篇博客,用以规划我的编程人生

    本人编程小白.第一次写技术博客,希望制定一个学习计划,让自己慢慢成长为一名优秀的程序猿. 学习方向是成为一名全栈工程师. 前端方面:会用bootstrap设计网页,会用jQuery完成动作. 后端方面 ...

  7. Python中的TCP的客户端UDP学习----第一篇博客

    Python中的TCP的客户端&UDP学习--第一篇博客 PS: 每日的怼人句子"我真想把我的脑子放到你的身体里,让你感受一下智慧的光芒" 先说UDP流程 发送: 创建套接 ...

  8. “Hello, my first blog”------第一篇博客的仪式感

    本人在校大学生一枚,开通博客,主要是想记录自己的学习过程,分享自己的学习经历.记得大一的时候,很多不懂的操作和知识,都是在博客上找到了相应的解决办法.但比较讽刺的是,很多时候,曾经解决了的问题,当再次 ...

  9. 第一篇博客《import tensorflow的问题解决》

    第一篇博客<import tensorflow的问题解决> 参考文章: (1)第一篇博客<import tensorflow的问题解决> (2)https://www.cnbl ...

  10. 第一篇博客——自我介绍篇

    首先介绍下自己.我来自山东理工大学,专业为矿业工程,是一名非科班专业应届毕业生. 这是我的第一篇博客.之前从来没接触过博客,一直都是在笔记本记录,沾边一点的也就是发发朋友圈.今天是我写博客的第一天,从 ...

最新文章

  1. Prioritize your work by your title
  2. 基于LBS的热点店铺搜索
  3. 10.9 kill以及raise函数
  4. MATLAB的xlsread无法读入数据问题
  5. 7-9 设计一个能处理异常的Loan类 (20 分)
  6. dbms_job涉及到的知识点
  7. UILabel自适应高度和自动换行
  8. 大新闻!Magic Leap造假,HoloLens即将入华商用
  9. Linux 命令之 apt -- Debian Linux 新一代的软件包管理工具
  10. Java的HttpURLConnection通过POST请求中文乱码
  11. 看看大神是如何计算32位数中‘1’的个数
  12. LeetCode 378. 有序矩阵中第K小的元素(二分查找)
  13. 女朋友拿走程序员的什么最不能忍?直到程序员看到这个,无法忍受!
  14. 大数乘加运算然后取模 c++_技术解析 | FPGA运算单元可支持高算力浮点
  15. 数字信号处理2:傅里叶变换
  16. 带你通俗理解https
  17. spring管理bean容器(笔记)[继]
  18. 【新手速成】菜鸟如何在三天内完成系统开发
  19. mysql用户角色权限表设计_用户角色权限设计(转)
  20. 计算机电源如何选配,自己组装电脑时,该怎么选择电源才合适?

热门文章

  1. excel插入html文本,带有标签的HTML文本,用于Excel单元格中的格式化文本
  2. PFLD+GhostNet+MobileOne=PFLD_GhostOne,重参数化让PFLD重生,精度提升超过4%,速度提升超过55%,代码已开源
  3. 网址、域名的区别(二)
  4. 带你秒懂STIL文件
  5. 程序运行闪图界面以及传感器
  6. 鸿蒙丹法 可练吗,“狐仙拜月”是狐狸修道炼丹的法门,其实很多修道人也练过这个功法!...
  7. 神经网络训练神器 tmux --网络掉线,训练不断
  8. 基于STM32单片机的大气压强检测仪(Proteus仿真+程序)
  9. 自己做量化交易软件(8)通通量化自编公式-仿通达信大智慧公式指标
  10. 在条码软件中怎样制作独特的条形码图案