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);
long time = new Date().getTime();
String tmpStr = String.valueOf(time);
String last4Str = tmpStr.substring(tmpStr.length() - 5);
int notificationId = Integer.valueOf(last4Str);
// // 해당 어플을 실행하는 이벤트를 하고싶을 때 아래 주석을 풀어주세요
PendingIntent pendingIntent;
String url = "section=" + section + "&category=" + category + "&no="
+ no;
int titleBar = DataManager.getCodeModel(Integer.parseInt(category)).getTitleText();
pendingIntent = PendingIntent.getActivity(
context,
notificationId,
new Intent(context, DetailNewsViewActivity.class)
.putExtra(KEY_SUB_URL, url)
.putExtra(KEY_SECTION, section)
.putExtra(KEY_CATEGORY, category)
.putExtra(KEY_TITLEBAR, titleBar)
.putExtra(KEY_SUBJECT, msg)
.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(notificationId, 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);
}
}
public interface NextListener {
public void next();
}
안녕하세요 GCM으로 푸시 사용중인데 앱을 처음 시작할 때 에러 종료가 되면서
int titleBar = DataManager.getCodeModel(Integer.parseInt(category)).getTitleText(); 이 부분에서 Integer.parseInt(category) 넘버포맷에러가 나네요.
근데 showMessage 이 함수는 푸시가 발송 됐을 때만 타는 거 아닌가요?
메인액티비티에서 regist 함수 빼곤 호출하는 게 없는데 계속 넘버포맷 nullException 뜨면서 종료가 되는데
디버깅 했을 때 showMessage를 타는 것도 아니구요..;
그래서 형변환 하는 부분을 기본값으로 0을 줬더니 아예 푸시 보낼 때 다이얼로그가 실행될 때 뜨네요.
이런 현상 겪으신 분들 있으신가요?