build.gradle sourceSets { main.jni.srcDirs = [] main.jniLibs.srcDirs = [‘libs‘] }
public class MyApplication extendsApplication { publicvoidonCreate() { super.onCreate(); JPushInterface.setDebugMode(true); JPushInterface.init(this); } }
public class MyReceiver extends BroadcastReceiver { @Override publicvoidonReceive(Context context, Intent intent) { System.out.println("接收到消息了。。。。"); Bundle bundle = intent.getExtras(); String type = bundle.getString(JPushInterface.EXTRA_EXTRA); System.out.println("接收到消息了==="+type); } }
用户点击的时候的处理
else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { Log.d(TAG, "[MyReceiver] 用户点击打开了通知"); Log.d(TAG, "[MyReceiver] 用户点击打开了通知: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); try { String json = bundle.getString(JPushInterface.EXTRA_EXTRA); JSONObject jsonObject = new JSONObject(json); String newsurl = jsonObject.optString("newsurl"); if(TextUtils.isEmpty(newsurl)){ newsurl = "http://10.0.2.2:8080/zhbj/10012/724D6A55496A11726628.html"; } //打开自定义的Activity Intent i = new Intent(context, NewsDetailActivity.class); i.putExtra("url",newsurl); // i.putExtras(bundle); //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(i); } catch (JSONException e) { e.printStackTrace(); }
时间: 2024-10-13 06:05:37