1. 程式人生 > >極光推送能收到通知卻收不到自定義訊息

極光推送能收到通知卻收不到自定義訊息

public class MyJPushReceiver extends BroadcastReceiver {
private static String TAG = “pushreceiver”;
public MyJPushReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
    // TODO: This method is called when the BroadcastReceiver is receiving
    // an Intent broadcast.
    Bundle bundle = intent.getExtras();
    Log.d(TAG, "onReceive - " + intent.getAction());

    if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
    } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent
            .getAction())) {
        // 自定義訊息不會展示在通知欄,完全要開發者寫程式碼去處理
        String content = bundle.getString(JPushInterface.EXTRA_MESSAGE);
        String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);

        System.out.println("收到了自定義訊息--------->:"+ content);
        System.out.println("收到了自定義訊息@@訊息extra是:"+ extra);

        //**************解析推送過來的json資料並存放到集合中 begin******************
        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject jsonObject;
        try {
            jsonObject = new JSONObject(extra);
            String type = jsonObject.getString("type");
            map.put("type", type);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        map.put("content", content);
        //獲取接收到推送時的系統時間
        Calendar rightNow = Calendar.getInstance();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        String date = fmt.format(rightNow.getTime());
        map.put("date", date);

// MyApp.data.add(map);
//****解析推送過來的json資料並存放到集合中 end******************
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent
.getAction())) {
System.out.println(“收到了通知”);
// 在這裡可以做些統計,或者做些其他工作
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent
.getAction())) {
System.out.println(“使用者點選打開了通知”);
// 在這裡可以自己寫程式碼去定義使用者點選後的行為
Intent i = new Intent(context, MainActivity.class); // 自定義開啟的介面
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Log.d(TAG, “Unhandled intent - ” + intent.getAction());
}
}
// throw new UnsupportedOperationException(“Not yet implemented”);
}

配置檔案