android极光推送声音,Android 极光推送JPush---自定义提示音

public classMyReceiver extends BroadcastReceiver {private static final String TAG = MyReceiver.class.getSimpleName();private static final int NOTIFICATION_SHOW_SHOW_AT_MOST = 3; //推送通知最多显示条数

@Overridepublic voidonReceive(Context context, Intent intent) {

Bundle bundle=intent.getExtras();// if(intent.getAction().equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)){

Log.i(TAG,"接收到了通知");

String title=bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);

String content=bundle.getString(JPushInterface.EXTRA_ALERT);

String extra=bundle.getString(JPushInterface.EXTRA_EXTRA);

Log.i(TAG,"标题:【"+title+"】,内容:【"+content+"】,附加参数:【"+extra+"】");

}else if(intent.getAction().equals(JPushInterface.ACTION_MESSAGE_RECEIVED)){

Log.i(TAG,"接收到了消息");

String message=bundle.getString(JPushInterface.EXTRA_MESSAGE);

processCustomMessage(context, bundle);

Log.i(TAG,"接收到的消息是:【"+message+"】");

}else if(intent.getAction().equals(JPushInterface.ACTION_NOTIFICATION_OPENED)){

Log.i(TAG,"用户正在打开通知");

}

}/**

* 实现自定义推送声音

* @param context

* @param bundle*/

private voidprocessCustomMessage(Context context, Bundle bundle) {

NotificationCompat.Builder notification= newNotificationCompat.Builder(context);

String title=bundle.getString(JPushInterface.EXTRA_TITLE);

String msg=bundle.getString(JPushInterface.EXTRA_MESSAGE);

String extras=bundle.getString(JPushInterface.EXTRA_EXTRA);

Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon_mdpi);

Intent mIntent= new Intent(context,****.class);

mIntent.putExtras(bundle);

mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent= PendingIntent.getActivity(context, 0, mIntent, 0);

notification.setContentIntent(pendingIntent)

.setAutoCancel(true)

.setContentText(msg)

.setContentTitle(title.equals("") ? "title": title)

.setSmallIcon(R.mipmap.icon_mdpi)

.setLargeIcon(bitmap)

.setNumber(NOTIFICATION_SHOW_SHOW_AT_MOST);

Log.e(TAG,"processCustomMessage: extras----->" +extras);if (!TextUtils.isEmpty(extras)) {try{

JSONObject extraJson= newJSONObject(extras);if (null != extraJson && extraJson.length() > 0) {

String sound= extraJson.getString("sound");if("1".equals(sound)){

notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.default_push_sound));

}else{

notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.test));

}

}

}catch(JSONException e) {

e.printStackTrace();

}

}

NotificationManager notificationManager=(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(NOTIFICATION_SHOW_SHOW_AT_MOST, notification.build());//id随意,正好使用定义的常量做id,0除外,0为默认的Notification

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值