android+极光推送配置,极光推送配置(Android Studio),亲测有效

6741e55a7c79fcc14ed9a2ab17c7f090.png

bddbfa8c5718561da6d51c43e985f226.png

fefbb0becb962d979c6ca4dafe3b68c4.png

06a33fc1f9a5d82ad859fd6fc6520774.png

eac040ef1deaacc589f91468429832f1.png

85f31bc2e053ffeea9d42772bae5c09a.png

461792b329f21297c9c32bad14bb9c25.png

822b360f22ffc818729c81edae31d499.png

进行到这里就可以接收到通知了,但是如果你还想根据接收的消息做点什么

step8:

public class MyReceiver extends BroadcastReceiver {

private static final String TAG = "MyReceiver";

private NotificationManager nm;

@Override

public void onReceive(Context context, Intent intent) {

if (null == nm) {

nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

}

Bundle bundle = intent.getExtras();

// Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));

if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {

Log.d(TAG, "JPush 用户注册成功");

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

Log.d(TAG, "接受到推送下来的自定义消息");

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

Log.d(TAG, "接受到推送下来的通知");

receivingNotification(context,bundle);

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

Log.d(TAG, "用户点击打开了通知");

openNotification(context,bundle);

} else {

Log.d(TAG, "Unhandled intent - " + intent.getAction());

}

}

private void receivingNotification(Context context, Bundle bundle){

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

Log.d(TAG, " title : " + title);

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

Log.d(TAG, "message : " + message);

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

Log.d(TAG, "extras : " + extras);

}

private void openNotification(Context context, Bundle bundle){

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

String myValue = "";

try {

JSONObject extrasJson = new JSONObject(extras);

myValue = extrasJson.optString("myKey");

} catch (Exception e) {

Log.w(TAG, "Unexpected: extras is not a valid json", e);

return;

}

Log.d(TAG, "myValue : " + myValue);

if (TYPE_THIS.equals(myValue)) {

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

mIntent.putExtras(bundle);

mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(mIntent);

} else if (TYPE_ANOTHER.equals(myValue)){

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

mIntent.putExtras(bundle);

mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(mIntent);

}

}

}

step9:最后别忘了在清单中注册

android:name="com.psm.admininstrator.lele8teach.MyReceiver"

android:exported="false"

android:enabled="true">

原博客地址:https://blog.csdn.net/jinjianghai/article/details/80336099

标签:Log,mIntent,bundle,TAG,Studio,context,intent,Android,亲测

来源: https://www.cnblogs.com/wzqnxd/p/10511607.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值