Back to project page voltag.
The source code is released under:
MIT License
If you think the Android project voltag 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 edu.purdue.voltag; //from ww w .ja v a 2 s . co m import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.util.Log; import org.json.JSONException; import org.json.JSONObject; import java.util.Iterator; public class MyCustomReceiver extends BroadcastReceiver { private static final String TAG = "MyCustomReceiver"; @Override public void onReceive(Context context, Intent intent) { try { String action = intent.getAction(); String channel = intent.getExtras().getString("com.parse.Channel"); if (channel == null) { return; } JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); Log.d(TAG, "got action " + action + " on channel " + channel + " with:"); Iterator itr = json.keys(); while (itr.hasNext()) { String key = (String) itr.next(); Log.d(TAG, "..." + key + " => " + json.getString(key)); } Intent i = new Intent(); i.setClassName("edu.purdue.voltag", "edu.purdue.voltag.MainActivity"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentText(intent.getExtras().getString("alert")); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); // Sets an ID for the notification int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); Intent updateIntent = new Intent("edu.purdue.voltag.UPDATE"); //put whatever data you want to send, if any //updateIntent.putExtra("message", message); //send broadcast context.sendBroadcast(updateIntent); } catch (JSONException e) { Log.d(TAG, "JSONException: " + e.getMessage()); } } }