Advertisement
Guest User

GCMIntentService

a guest
Jan 22nd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 KB | None | 0 0
  1. package com.wmakit.samataxi.gcm;
  2.  
  3. import android.app.IntentService;
  4. import android.app.Notification;
  5. import android.app.NotificationChannel;
  6. import android.app.NotificationManager;
  7. import android.app.PendingIntent;
  8. import android.content.Context;
  9. import android.content.Intent;
  10. import android.graphics.BitmapFactory;
  11. import android.media.Ringtone;
  12. import android.media.RingtoneManager;
  13. import android.net.Uri;
  14. import android.os.Build;
  15. import android.os.Bundle;
  16. import android.os.Vibrator;
  17. import android.support.v4.app.NotificationCompat;
  18. import android.support.v4.content.LocalBroadcastManager;
  19. import android.util.Log;
  20. import android.widget.Toast;
  21.  
  22. import com.google.android.gms.gcm.GcmListenerService;
  23. import com.wmakit.samataxi.R;
  24. import com.wmakit.samataxi.RequestService;
  25. import com.wmakit.samataxi.activities.NotificationActivity;
  26. import com.wmakit.samataxi.activities.SplashActivity;
  27. import com.wmakit.samataxi.activities.WaitDriverConfirmActivity;
  28. import com.wmakit.samataxi.config.Constant;
  29. import com.wmakit.samataxi.config.GlobalValue;
  30. import com.wmakit.samataxi.config.PreferencesManager;
  31. import com.wmakit.samataxi.modelmanager.ModelManager;
  32. import com.wmakit.samataxi.modelmanager.ModelManagerListener;
  33. import com.wmakit.samataxi.modelmanager.ParseJsonUtil;
  34. import com.wmakit.samataxi.object.CurrentOrder;
  35. import com.wmakit.samataxi.service.LaunchAnswerCallActivityService;
  36. import com.wmakit.samataxi.volleynetwork.ControllerRequest;
  37.  
  38. import org.json.JSONException;
  39. import org.json.JSONObject;
  40.  
  41. import java.util.Random;
  42.  
  43. import static android.app.Notification.CATEGORY_CALL;
  44. import static com.wmakit.samataxi.config.Constant.ECO_SUB_TYPE_DELIVERY;
  45. import static com.wmakit.samataxi.config.Constant.KEY_ADDITIONAL_DISTANCE;
  46. import static com.wmakit.samataxi.config.PreferencesManager.ECO_SUB_TYPE;
  47.  
  48. /**
  49.  * {@link IntentService} responsible for handling GCM messages.
  50.  */
  51. public class GCMIntentService extends GcmListenerService {
  52.  
  53.     private final String TAG = "GCMIntentService";
  54.     public static final String KEY_DATA = "data";
  55.     public static final String KEY_BODY = "body";
  56.     public static final String KEY_ACTION = "action";
  57.     private static int NOTIFICATION_ID = 0;
  58.     private static int NOTIFICATION_HEAD_ID = 1000;
  59.     private static String NOTIFICATION_CHANEL_ID = "chanel_01";
  60.     private static String NOTIFICATION_CHANEL_NAME = "Alerte";
  61.     private PreferencesManager preferencesManager = PreferencesManager
  62.             .getInstance(this);
  63.  
  64.     @Override
  65.     public void onMessageReceived(String from, Bundle data) {
  66.         Log.e(TAG, "onMessage: " + data);
  67.         processReciverPush(this, data);
  68.     }
  69.  
  70.  
  71.     private void processReciverPush(Context context, Bundle data) {
  72.         String action = data.getString(KEY_ACTION);
  73.  
  74.         Log.e(TAG, "onMessage action: " + action);
  75.         Intent broadCastIntent;
  76.  
  77.         if (null == action) {
  78.             return;
  79.         }
  80.         switch (action) {
  81.             // Done
  82.             case Constant.ACTION_CALL_RECEIVED:
  83.  
  84.                 try {
  85.                     JSONObject jsonObject = new JSONObject(data.getString(KEY_DATA));
  86.                     Log.e(TAG, "onMessage gcm: " + jsonObject.getString("userName"));
  87.  
  88.                     Intent intent = new Intent(this, LaunchAnswerCallActivityService.class);
  89.                     intent.putExtra("id", jsonObject.getString("id"));
  90.                     intent.putExtra("userName", jsonObject.getString("userName"));
  91.                     intent.putExtra("image", jsonObject.getString("image"));
  92.                     intent.putExtra("phone", jsonObject.getString("phone"));
  93.                     startService(intent);
  94.                 } catch (Exception e) {
  95.                     e.printStackTrace();
  96.                 }
  97.                 break;
  98.             case Constant.NOTIFY_PARTENER_SINCH_CALL_HANGUP:
  99.                 broadCastIntent = new Intent();
  100.                 broadCastIntent.setAction(Constant.NOTIFY_PARTENER_SINCH_CALL_HANGUP);
  101.                 sendBroadcast(broadCastIntent);
  102.                 break;
  103.  
  104.  
  105.         }
  106.     }
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement