jpush自定义推送声音
来源:互联网 发布:luastudio for mac 编辑:程序博客网 时间:2024/06/18 03:34
public class MyReceiver extends BroadcastReceiver { public static final String TAG = "Jpush"; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();// Log.e(TAG, "收到的所有信息----->>>> " + intent.getAction() + ", extras: " + printBundle(bundle)+"<<<<<---------"); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); Log.e(TAG, "[MyReceiver] 接收Registration Id : " + regId); //保存ID到服务器 } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {//自定义消息(需要自定义notifition,或者其他逻辑处理) } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {//收到了通知(自带notifition) int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); Intent toOrderActivity = new Intent(); toOrderActivity.setAction(OrderActivity.BROADCAST_ACTION); toOrderActivity.putExtra("msg", "isBroad"); context.sendBroadcast(toOrderActivity); Log.e("guangbo",toOrderActivity.getStringExtra("msg"));// Toast.makeText(CustomApplication.getContext(),"[MyReceiver] 接收到推送下来的通知:"+bundle.getString(JPushInterface.EXTRA_TITLE),Toast.LENGTH_SHORT); Log.e(TAG, "[MyReceiver] 接收到推送下来的通知: " + bundle.getString(JPushInterface.EXTRA_TITLE)); Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); processCustomMessage(context,bundle); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {//点击了通知消息 boolean isAlive = (boolean) SharedPreferencesUtils.getParam(CustomApplication.getContext(), "isAlive", false); String extra = (String) bundle.get(JPushInterface.EXTRA_EXTRA);// Log.e(TAG, "[MyReceiver] 用户点击打开了通知"+extra); try { JSONObject dataJson = new JSONObject(extra); String pushFlag = dataJson.optString("push_flag"); if (!TextUtils.isEmpty(pushFlag)) { if (!pushFlag.equals("1")) { SharePreferecesUtils_MyWork.setParam(CustomApplication.getContext(), "qiehuan", 2); } else { SharePreferecesUtils_MyWork.setParam(CustomApplication.getContext(), "qiehuan", 1); } } else { SharePreferecesUtils_MyWork.setParam(CustomApplication.getContext(), "qiehuan", 1); } if (isAlive) { Intent intent1 = new Intent(context, MainActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent1); } else { Intent intent1 = new Intent(context, LoginActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent1); } } catch (JSONException e) { e.printStackTrace(); } } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { Log.e(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.e(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); } else { Log.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); } } private void processCustomMessage(Context context,Bundle bundle) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder notification = new NotificationCompat.Builder(context); notification.setAutoCancel(true) .setContentText("自定义推送声音") .setContentTitle("极光测试") .setSmallIcon(R.mipmap.ic_launcher); String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//获取音频文件路径,(在res文件夹下面创建一个raw文件夹,将需要的音频文件放进raw里面) notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.test)); Intent mIntent = new Intent(context,OrderActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0); notification.setContentIntent(pendingIntent); notificationManager.notify(2, notification.build()); }}
参考博客链接:http://www.jianshu.com/p/8e15ae0909d2
0 0
- jpush自定义推送声音
- Jpush 自定义推送声音
- Jpush 自定义推送声音
- ios 自定义推送声音
- 设置推送自定义声音
- 极光推送JPush---自定义提示音
- jpush推送
- jpush 推送
- JPush推送
- 开发笔记 - 自定义推送声音
- 推送通知自定义提示声音
- iOS 本地推送以及自定义推送声音
- 极光推送(JPush)通知与自定义消息的区别
- iOS开发之极光推送自定义推送声音
- 极光推送JPush
- 试用JPush极光推送
- JPUSH andoid推送开发
- JPush 服务器消息推送
- Android 反射 换一种方式编程
- java中subSequence方法和subString方法的区别
- leetcode13. Roman to Integer
- 深度优先遍历/广度优先遍历(递归+非递归java实现)
- 【转】sql之left join、right join、inner join的区别
- jpush自定义推送声音
- 二叉树
- 杂记4
- 3、文件相关命令
- java.lang.NoSuchFieldError: VERSION_2_3_0 报错解决方案
- Linux command note
- 提高C#编程水平的50个要点 之三“在 as 和 强制类型转换之间,优先使用 as 操作符”。
- 1118. Birds in Forest (25) PAT 甲级
- 20位活跃在Github上的国内技术大牛