2014-01-15 2 views
0

위치 기반 푸시 알림에 내 Android 앱을 등록하고 싶습니다.기기 톱 바에 푸시 알림을 로컬로 표시합니다.

여기

좋은 아키텍처 아이디어 여기에 몇 가지 좋은 팁을 얻었다.

정확하게 이해하면 GCM을 사용하지 않아도되지만 자체 서버를 사용합니다. 권리?

서버로 내 위치를 전송하고 JSON 응답을받은 후 장치 상단 막대에 로컬로 표시하려면 어떻게해야합니까?

답변

0

수신자가 메시지를 수신 할 때 알림을 트리거하는 수신자를 만듭니다. 다음 코드를 사용하여 알림을 만들 수 있습니다.

import android.app.Notification; 
    import android.app.NotificationManager; 
    import android.app.PendingIntent; 

    private NotificationManager mNotificationManager; 
    NotificationCompat.Builder builder; 
    Context ctx; 
    private void sendNotification(Intent receivedIntent) { 

     mNotificationManager = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent intent = new Intent(ctx, ReceiveNotification.class);// this will open the class receiveNotification when the notification is clicked 
     intent.putExtra("author", receivedIntent.getStringExtra("author")); 

     PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent , 0); 
     NotificationCompat.Builder noti = new NotificationCompat.Builder(ctx) 
     .setSmallIcon(R.drawable.ic_launcher)  // if you want to include an icon 
     .setContentTitle("your app name") 
     .setStyle(new NotificationCompat.BigTextStyle() 
     .bigText("By: " + receivedIntent.getStringExtra("name"))) 
     .setWhen(System.currentTimeMillis()) 
     .setTicker("By: " + receivedIntent.getStringExtra("name")) 
     .setDefaults(Notification.DEFAULT_SOUND) 
     .setContentText("your message"); 
     noti.setContentIntent(pendingIntent); 
     mNotificationManager.notify(1, noti.build()); 

    } 
+0

btw 어떻게 수신자가 서버로부터 메시지를 받습니까? 어떤 이벤트에 \ intent를 등록해야합니까? –

관련 문제