1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android极光推送声音 Android 极光推送JPush---自定义提示音

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

时间:2023-10-21 12:12:45

相关推荐

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

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。