public class GCMIntentService extends GCMBaseIntentService implements NetDefine {
private static final String TAG = "GCM Tutorial::Service";
public static NextListener listener;
public GCMIntentService() {
super(SENDER_ID);
}
Setting mSetting;
@Override
protected void onMessage(Context context, Intent intent) {
mSetting = new Setting(context);
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
String option_push = mSetting.getString(KEY_PUSHCH, "");
if ("true".equals(option_push)) {
showMessage(context, intent);
}
}
}
@Override
protected void onError(Context context, String msg) {
// TODO Auto-generated method stub
Log.w(TAG, "onError!! " + msg);
}
@Override
protected void onRegistered(Context context, String regID) {
// TODO Auto-generated method stub
if (listener != null) {
listener.next();
listener = null;
}
mSetting = new Setting(context);
mSetting.input(KEY_GCM_REGI_ID, regID);
}
@Override
protected void onUnregistered(Context context, String regID) {
// TODO Auto-generated method stub
Log.w(TAG, "onUnregistered!! " + regID);
}
public void showToast() {
Toast.makeText(this, "RegID 등록 완료", Toast.LENGTH_SHORT).show();
}
private void showMessage(Context context, Intent intent) {
String title = intent.getStringExtra(KEY_TITLE);
String msg = intent.getStringExtra(KEY_MSG);
String section = intent.getStringExtra(KEY_SECTION);
String category = intent.getStringExtra(KEY_CATEGORY);
String no = intent.getStringExtra(KEY_NO);
String fairurl = intent.getStringExtra(KEY_FAIRURL);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Activity.NOTIFICATION_SERVICE);
// // 해당 어플을 실행하는 이벤트를 하고싶을 때 아래 주석을 풀어주세요
PendingIntent pendingIntent;
String url = "section=" + section + "&category=" + category + "&no="
+ no;
int titleBar = DataManager.getCodeModel(Integer.valueOf(category)).getTitleText();
pendingIntent = PendingIntent.getActivity(
context,
0,
new Intent(context, DetailNewsViewActivity.class)
.putExtra(KEY_SUB_URL, url)
.putExtra(KEY_SECTION, section)
.putExtra(KEY_CATEGORY, category)
.putExtra(KEY_TITLEBAR, titleBar)
.putExtra(KEY_CHANNEL, true)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification();
notification.icon = R.drawable.icon;
notification.when = System.currentTimeMillis();
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, title, msg, pendingIntent);
notificationManager.notify(0, notification);
Intent i = new Intent(context, GCMMessageView.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra(KEY_TITLEBAR, titleBar);
i.putExtra(KEY_MSG, msg);
i.putExtra(KEY_SUB_URL, url);
i.putExtra(KEY_SECTION, section);
i.putExtra(KEY_CATEGORY, category);
i.putExtra(KEY_FAIRURL, fairurl);
context.startActivity(i);
{
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Wake Android Device when notification received
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock mWakelock = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
mWakelock.acquire();
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
mWakelock.release();
}
};
vibe.vibrate(1000);
timer.schedule(task, 5000);
}
}
현재 GCMINTENTSERVICE 소스가 이렇게 되어있는데요. php로 msg section category no 네가지 파라미터를 보내서 이걸 받아서 푸시를 보내고 있는데 노티피케이션 목록에 2개 이상의 푸시메시지가 쌓여있을 때 어떤걸 누르던지 무조건 마지막에 보냈던 위치로 이동이 되네요. 어떻게 해야 할까요?