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

GCMIntentService 질문이있습니다.

0 추천
public class GCMIntentService extends GCMBaseIntentService {

    @SuppressWarnings("hiding")
    private static final String TAG = "GCMIntentService";

    public GCMIntentService() {
        super(SENDER_ID);
    }


    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        
        TextView textView1;
        
Bundle b = intent.getExtras();

Iterator<String> iterator = b.keySet().iterator();

String key = iterator.next();
String value = b.get(key).toString();

if (key.equals("msg")) {
 Log.d(TAG, "onMessage. "+key+" : "+value);
}

displayMessage(context, value);
generateNotification(context, value);

LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.custom_toast,
                (ViewGroup)findViewById(R.id.toast_layout_root));
        Toast toast = new Toast(getApplicationContext());
//         textView1 = (TextView)layout.findViewById(R.id.textView1);
//         textView1.setText(value);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();

AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

switch (audioManager.getRingerMode()) {
case AudioManager.RINGER_MODE_VIBRATE://진동

Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);         
// long[] pattern = {1000, 200, 1000, 2000, 1200};          // 진동, 무진동, 진동 무진동 숫으로 시간을 설정한다.
// vibe.vibrate(pattern, 4);                                         // 패턴을 지정하고 반복횟수를 지정
vibe.vibrate(1000);   //1초 동안 진동이 울린다.

break;
case AudioManager.RINGER_MODE_NORMAL://소리
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(),RingtoneManager.TYPE_NOTIFICATION);
Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);
ringtone.play();
break;
case AudioManager.RINGER_MODE_SILENT://무음

break;
}
    }
    private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_stat_gcm;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, VTPMsMain_Activity.class);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
GCMIntentService 에는 이렇게 소스가 들어가있습니다.
제가 하려고 하는것은 gcm 메세지를 받게되면 toast를 띄우는 것인데 일반 toast말고 customtoast를 사용하려고 합니다.
하지만 
View layout = inflater.inflate(R.layout.custom_toast,
                (ViewGroup)findViewById(R.id.toast_layout_root));
이 부분에서 null이 들어가서 사용이 불가능한데 다른방법이 뭐가 있을지 한마디씩 부탁드리겠습니다.
 
Noswind (2,330 포인트) 님이 2014년 8월 7일 질문
gcm은 잘 되는데 커스텀 토스트가 안되는건가요?
토스트 자체는 됩니다.
하지만 custom toast가 안됩니다..
toast자체도 다른방법으로 하였습니다.
gcm도 잘 되고, toast도 잘 된다면 제목을 완전 잘못 쓰셨네요. 그냥 toast에 view를 넣는 방법이 있는지를 묻는게 더 나을 것 같아요

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...