Back to project page tehran_traffic_map.
The source code is released under:
MIT License
If you think the Android project tehran_traffic_map listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.tehran.traffic.service; /*from w w w . jav a2 s . co m*/ import android.app.IntentService; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import com.google.android.gms.gcm.GoogleCloudMessaging; import com.tehran.traffic.R; import com.tehran.traffic.ui.MainActivity; import java.util.Calendar; public class GcmIntentService extends IntentService { public static final int NOTIFICATION_ID = 1; NotificationCompat.Builder builder; String TAG = "Px GCM IntentService"; private NotificationManager mNotificationManager; public GcmIntentService() { super("GcmIntentService"); } @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. String newms = extras.getString("message").toString(); sendNotification(newms); } } GcmBroadcastReceiver.completeWakefulIntent(intent); } private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("alert", "1"); intent.putExtra("msg", msg); PendingIntent contentIntent = PendingIntent.getActivity(this, (int) Calendar.getInstance().getTimeInMillis(), intent, 0); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getResources().getString(R.string.app_name)) .setSound(uri) .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .setContentText(msg).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }