极光推送文档上注册这些就不说了
写一些自己觉得有用的
1.广播,接到通知以后的处理
public class JPushReceiver 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();
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, "接受到推送下来的通知");
} 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 openNotification(Context context, Bundle bundle){
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
String url = "";
String title="";
try {
JSONObject extrasJson = new JSONObject(extras);
Log.i("extrasJson",extrasJson.toString());
String back=extrasJson.optString("url");
String top= back.substring(0,3);
Log.i("topff",top);
if(top.equals("app")){
String exittop=back.substring(6);
Log.i("exittop",exittop);
// ios.YYVoucherViewController.android.MyCouponActivity?
String exitend= exittop.substring(0,exittop.indexOf("?"));
Log.i("exitend",exitend);
//ios.YYVoucherViewController.android.MyCouponActivity
String[] strs=exitend.split("\\.");
String togoclass=strs[3].toString();
Intent intent2 =new Intent(context, Class.forName("com.yylc.yylearncar.view.activity.mine."+togoclass));
context.startActivity(intent2);
}else {
url = extrasJson.optString("url");
title = extrasJson.optString("title");
Intent intent=new Intent(context, WebActivity.class);
intent.putExtra("url",url);
intent.putExtra("title",title);
Log.i("extrasJson2",url);
Log.i("extrasJson2",title);
context.startActivity(intent);
}
} catch (Exception e) {
Log.d(TAG, "Unexpected: extras is not a valid json", e);
return;
}
}
}
记得在配置文件之中,把这个广播注册了
2.如果想精准推送,需要设置alias
JPushInterface.setAlias(getActivity(), 100, MD5Util.MD5(MD5Util.MD5(account)));