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

FCM과같은 서비스에서 메세지를 받았을때 앱내에서 다이얼로그 띄우는 방법이 궁금합니다

0 추천

현재 앱이 꺼져있을때 노티가와서 PendingIntent를 이용해 노티를 클릭시 메인화면을 띄우고 다이얼로그를 띄울 수 있는상태인데요

앱이 켜있는상태에서는 노티를 보내지않고 바로 다이얼로그를 띄우고싶은데 현재 떠있는 화면에 다이얼로그를 띄우는방법이 궁금합니다 

컨텍스트를이용해 다이얼로그를 띄우려했었는데 서비스 안에서 getApplicationContext를 한다고해서 현재 떠있는 화면의 컨텍스를 받아오는것이 아니라 다이얼로그를 띄우기가 힘드네여 

두번쨰 방법으로 Theme를 다이얼로그로한 액티비티를 띄우는데 현재화면이 아닌 런처 화면에서 다이얼로그가 띄어집니다 

혹시 해결방법좀 알려주시면 감사하겠습니다 ㅜㅜ

GCM에서 저와 같은 문제질문입니다 

http://www.androidside.com/bbs/board.php?bo_table=b49&wr_id=124364

 

소스코드

private void sendNotification(NotiApplyItem item) {

        boolean isOpen; //앱이 포그라운드 상태인지
        isOpen = isAppOpened();
        if (isOpen == true) {
            Intent intent = new Intent(this, PopupApplyActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//            intent.putExtras(bun);
            PendingIntent pie= PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            try {
                pie.send();
            } catch (PendingIntent.CanceledException e) {

            }
           

        } else {
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("notiItem", item);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_ONE_SHOT);

            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(item.getMessage())
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

//        Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
//        vibrator.vibrate(1000);
            // 잠든 단말을 깨워라.
            PushWakeLock.acquireCpuWakeLock(this);
            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    PushWakeLock.releaseCpuLock();
                }
            };
            Timer timer = new Timer();
            timer.schedule(task, 500);

            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            notificationManager.notify(1, notificationBuilder.build());
        }

    }

짜녁 (120 포인트) 님이 2016년 12월 9일 질문

1개의 답변

0 추천

안녕하세요

저도 예전에 GCM으로 개발했을때 안됐던 것 같아서

쓰레드를해서 돌렸던 기억이 있습니다. 과거 소스를 보니 그렇게 되어 있네요^^

protected void onMessage(Context context, Intent intent) << 여기에서 GET_GCM() 메소드 호출하시면 됩니다. 

도움되시길 바라며 한번해보세요!

public void GET_GCM() {

		Thread thread = new Thread(new Runnable() {
			public void run() {

				handler.sendEmptyMessage(0);
			}
		});
		thread.start();
	}

	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {

			// sendNotification(NotiApplyItem item) << 메소드 호출
			msg = null;
		}
	};

 

히로시 (10,800 포인트) 님이 2016년 12월 12일 답변
...