Android Open Source - bodyguard Gcm Broadcast Receiver






From Project

Back to project page bodyguard.

License

The source code is released under:

GNU General Public License

If you think the Android project bodyguard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.bodyguard;
/*  ww w  .  ja va  2s .  c o  m*/
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    String serverUri = "http://192.168.103.124:9000/userinformation/";

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public void onReceive(Context context, Intent intent)
  {
      // Explicitly specify that GcmIntentService will handle the intent.
      ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
      // Start the service, keeping the device awake while it is
      // launching.
      startWakefulService(context, (intent.setComponent(comp)));
      ResultActivity.phNumber = intent.getStringExtra("phoneNumber");
      ResultActivity.latitude = intent.getStringExtra("latitude");
      ResultActivity.longitude = intent.getStringExtra("longitude");

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

      Intent intent1 = new Intent(context, ResultActivity.class);
      PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent1, 0);

      Notification n = new Notification.Builder(context).setContentTitle("Somebody is in risk..Please help!!!")
        .setDefaults(Notification.DEFAULT_ALL)
        .setSmallIcon(R.drawable.logo)
        .setContentIntent(pIntent).setAutoCancel(true).getNotification();
      notificationManager.notify(0, n);

  }

    /**
     * Issues a notification to inform the user that server has sent a message.
     */
    private static void generateNotification(Context context, String message)
  {
      int icon = R.drawable.ic_launcher;
      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, MainActivity.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;

      // Play default notification sound
      notification.defaults |= Notification.DEFAULT_SOUND;

      // Vibrate if vibrate is enabled
      notification.defaults |= Notification.DEFAULT_VIBRATE;
      notificationManager.notify(0, notification);

  }
}




Java Source Code List

.BodyGuardActivity.java
com.example.bodyguard.AlertDialogManager.java
com.example.bodyguard.CommonUtilities.java
com.example.bodyguard.ConnectionDetector.java
com.example.bodyguard.CustomGeoCoding.java
com.example.bodyguard.DirectionsJSONParser.java
com.example.bodyguard.GPSTracker.java
com.example.bodyguard.GcmBroadcastReceiver.java
com.example.bodyguard.GcmIntentService.java
com.example.bodyguard.MainActivity.java
com.example.bodyguard.PlaceAutoComplete.java
com.example.bodyguard.PlaceDetails.java
com.example.bodyguard.Place.java
com.example.bodyguard.PlacesAutoCompleteAdapter.java
com.example.bodyguard.PlacesList.java
com.example.bodyguard.PollQRT.java
com.example.bodyguard.ResultActivity.java
com.example.bodyguard.SendLocationActivity.java
com.example.bodyguard.SplashScreen.java
com.example.bodyguard.StartActivity.java
com.example.bodyguard.UserInformation.java
com.example.bodyguard.WakeLocker.java