마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

카카오톡 처럼 탭바 혹은 버튼에 알림 badge 띄울려면....

0 추천
안녕하세요 오랫만에 들어왔습니다 ㅠㅠ;;;
 
궁금한내용은 다음과 같습니다.
현재 Push 알림이 오면 카카오톡 처럼 탭바나 버튼에 badge가 뜨도록 하고 싶은데...
아래 소스 방식으로 하면 화면에 badge 값이 나오지를 않습니다...
 
아래 방법은 SharedPreferences를 이용하여 GCMIntentService.java 에서 notification event 발생하면서 InActivity.java에있는 버튼 위에 badge값이 나오도록 하는 방식입니다.
 
아래 방식에서 어디가 잘못된건지 혹은 다른방법이 있는지좀 알려주세요....
 
 

Push 서비스에서 Push가 올 경우 카카오톡 처럼 어플 icon이 아닌 어플 안에 들어있는 버튼에

Badge를 추가 해주려고 하는데 잘 안되서 이렇게 글을 적습니다.

같은 .JAVA 에서는 버튼을 생성하여 클릭 시 뱃지 화면이 뜨고 있으나,

다른 .JAVA에서 푸시 노티피케이션 부분과 메시지 받는 부분에 이벤트 발생시 SharedPreferences를 이용하여 뱃지를 다른 .JAVA에 있는 버튼화면에 나오도록 설정 해보았으나 반응이 없습니다.

 

GCMIntentService.java 에는 setNotification과 onMessage가 있는데 각각 내용에는 아래와 같이 소스값을 작성하였습니다.

 

@Override
protected void onMessage(Context context, Intent intent) {
// TODO Auto-generated method stub
...

생략

...


if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
...

생략

...

if (BuildConfig.DEBUG)
Log.d(TAG, "GCMReceiver Message");
try {

// 뱃지 카운터를 올리기 위한 부분

// InActivity.java에 badge1 값을 가져와서 사용하겠다고 선언 하는 부분
InActivity BdK = new InActivity();
BadgeView bg = BdK.bd1;
InActivity BuK = new InActivity();
bg = new BadgeView(this, BuK.btn3);
bg.setBackgroundResource(R.drawable.badge);
nbs.setText("N");
nbs.setTextColor(Color.WHITE);
nbs.setTextSize(12);

SharedPreferences NB = getSharedPreferences("NB", MODE_PRIVATE);
boolean isMess = NB.getBoolean("isMess", true);
if(isMess) {

nbs.show();

isMess = true;
SharedPreferences.Editor sEdit = NB.edit();
sEdit.putBoolean("isMess", isMess);
sEdit.commit();
}
...
메시지 보여주는곳, 생략
...


} catch (Exception e) {
Log.e(TAG, "[onMess] : " + e.getMessage());
}
}
}

 

 

private void setNotification(Context context, String title, String message) {
NotificationManager notificationManager = null;
Notification notification = null;
try {

// 뱃지 부분 체크해 봐야 함

InActivity BdK = new InActivity();

BadgeView bg = BdK.bd1;
InActivity BuK = new InActivity();
bg = new BadgeView(this, BuK.btn3);
bg.setBackgroundResource(R.drawable.badge);
nbs.setText("N");
nbs.setTextColor(Color.WHITE);
nbs.setTextSize(12);

notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.icon, message, System.currentTimeMillis());
Intent intent = new Intent(context, WebBrowser3.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, title, message, pi);
notificationManager.notify(0, notification);

if(WB3.class.isAnnotation()) {

SharedPreferences NB = getSharedPreferences("NB", MODE_PRIVATE);
boolean isMess = NB.getBoolean("isMess", true);
if(isMess) {
// 뱃지 값 숨기기
bg.hide();
// 다이얼로그를 닫을 때 처리
isMess = true;
SharedPreferences.Editor sEdit = NB.edit();
sEdit.remove("isMess");
sEdit.commit();
}
}

} catch (Exception e) {
Log.e(TAG, "[setNotification] : " + e.getMessage());
}
}

 

InActivity.java 에는 다음과 같이 정의를 해 두었습니다.

 

public class InActivity extends Activity {

...

생략

...

 

Button btn3;
BadgeView bd1;


@Override
protected void onCreate(Bundle savedInstanceState) {

...

생략
...
btn3 = (Button) findViewById(R.id.am3);

// 뱃지에 들어가는 값 선언
bd1 = new BadgeView(this, btn3);
bd1.setBackgroundResource(R.drawable.badge);
bd1.setText("N");
bd1.setTextColor(Color.WHITE);
bd1.setTextSize(12);

 

btn3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if(bd1.isShown()) {
SharedPreferences NB = getSharedPreferences("NB", MODE_PRIVATE);
boolean isMessage = NB.getBoolean("isMess", true);
if(isMess) {
Intent int3 = new Intent(InActivity.this, WB3.class);
startActivity(int3);
// 뱃지 값 숨기기
bd1.hide();
// 다이얼로그를 닫을 때 처리
isMess = true;
SharedPreferences.Editor sEdit = NB.edit();
sEdit.remove("isMess");
sEdit.commit();
}

} else {

Intent int3 = new Intent(InActivity.this, WB3.class);
startActivity(int3);

}
}
});

 

...

생략

...

}

 

호리에상 (160 포인트) 님이 2013년 2월 22일 질문

 

같은 자바는 뭐고 다른 자바는 무슨 의미이신가요?
앱이 서로 틀리다는 말씀이신가요?

 

앱 개발할때 필요한 .java파일을 이야기 드리는 겁니다.

  

같은자바의 경우 하나의 자바파일 안에서 소스를 적었다고 보시면 되며,

다른자바는 자바파일이 두개있다고 보시면됩니다.

1개의 답변

0 추천
앱 개발할때 필요한 .java파일을 이야기 드리는 겁니다. 같은자바의 경우 하나의 자바파일 안에서 소스를 적었다고 보시면 됩니다. 다른자바는 자바파일이 두개있다고 보시면됩니다.
익명사용자 님이 2013년 2월 22일 답변
...