List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.inc.playground.playground.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from www . j a v a 2 s . co m*/ */ private void sendNotification(String message, String title, JSONObject inputJson) { globalVariables = ((GlobalVariables) this.getApplication()); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent iv = new Intent(); // if cancel event if (title.contains("requested")) { iv = new Intent(MyGcmListenerService.this, ApproveEventList.class); iv.putExtra("parent", "MyGcm"); iv.putExtra("inputJson", inputJson.toString()); } else { ArrayList<NotificationObject> notificationList = globalVariables.GetNotifications(); EventsObject curEvent = new EventsObject(); NotificationObject curNotification = new NotificationObject(); curNotification.setDescription(message); curNotification.setTitle(title); curNotification.setInputJson(inputJson); notificationList.add(curNotification); globalVariables.SetNotifications(notificationList); iv = new Intent(MyGcmListenerService.this, NotificationsList.class); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, iv, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.app.basarnas.fcm.MyFirebaseMessagingService.java
private void sendNotification() { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(Config.JSON_DATA_NOTIFICATION, jsonDataNotification); intent.setAction(Intent.ACTION_MAIN); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setStyle(new NotificationCompat.BigTextStyle().bigText(dataNotification.getText())) .setSmallIcon(R.mipmap.ic_launcher, 10) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(dataNotification.getTitle()) .setContentText(CommonUtilities.toHtml(dataNotification.getText())) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(Config.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build()); }
From source file:com.honkidenihongo.pre.service.JilFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param message FCM message body received. *///w ww .ja v a2 s. c o m private void sendNotification(String title, String message, long team_id, String team_name) { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(Definition.General.TEAM_ID, team_id); intent.putExtra(Definition.General.TEAM_NAME, team_name); intent.putExtra(Definition.General.PUSH_NOTIFICATION, true); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build()); }
From source file:net.olejon.mdapp.NotificationsFromSlvIntentService.java
@Override protected void onHandleIntent(Intent intent) { final Context mContext = this; final MyTools mTools = new MyTools(mContext); if (mTools.getDefaultSharedPreferencesBoolean("NOTIFICATIONS_FROM_SLV_NOTIFY") && mTools.isDeviceConnected()) { RequestQueue requestQueue = Volley.newRequestQueue(mContext); int projectVersionCode = mTools.getProjectVersionCode(); String device = mTools.getDevice(); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest( getString(R.string.project_website_uri) + "api/1/notifications-from-slv/?first&version_code=" + projectVersionCode + "&device=" + device, new Response.Listener<JSONArray>() { @SuppressLint("InlinedApi") @Override//from ww w .ja va2s. com public void onResponse(JSONArray response) { try { final JSONObject notifications = response.getJSONObject(0); final String title = notifications.getString("title"); final String message = notifications.getString("message"); final String lastTitle = mTools .getSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE"); if (!title.equals(lastTitle)) { if (!lastTitle.equals("")) { Intent launchIntent = new Intent(mContext, NotificationsFromSlvActivity.class); PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); NotificationManagerCompat notificationManager = NotificationManagerCompat .from(mContext); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( mContext); notificationBuilder.setWhen(mTools.getCurrentTime()) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PUBLIC) .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap) .setSmallIcon(R.drawable.ic_local_hospital_white_24dp) .setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLights(Color.BLUE, 1000, 2000).setTicker(title) .setContentTitle(title).setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentIntent(launchPendingIntent) .addAction(R.drawable.ic_notifications_white_24dp, getString( R.string.service_notifications_from_slv_read_more), launchPendingIntent); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } mTools.setSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE", title); } } catch (Exception e) { Log.e("NotificationsFromSlv", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("NotificationsFromSlv", error.toString()); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); } }
From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this); Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>()); if (x.size() == 0) { return;//from w ww . j a va 2s . com } String[] pairs = x.toArray(new String[x.size()]); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); String url = BASE_URL; for (String xx : pairs) { url += xx.replace("/", "_").toLowerCase(Locale.US) + "-"; } SimpleRequest reqSim = new SimpleRequest(); if (networkInfo != null && networkInfo.isConnected()) { JSONObject data = null; try { data = reqSim.makeRequest(url); } catch (JSONException e) { e.printStackTrace(); } if (data != null && data.optInt("success", 1) != 0) { ArrayList<Ticker> tickers = new ArrayList<>(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = data.keys(); iterator.hasNext();) { String key = iterator.next(); JSONObject pairData = data.optJSONObject(key); Ticker ticker = new Ticker(key); ticker.setUpdated(pairData.optLong("updated")); ticker.setAvg(pairData.optDouble("avg")); ticker.setBuy(pairData.optDouble("buy")); ticker.setSell(pairData.optDouble("sell")); ticker.setHigh(pairData.optDouble("high")); ticker.setLast(pairData.optDouble("last")); ticker.setLow(pairData.optDouble("low")); ticker.setVol(pairData.optDouble("vol")); ticker.setVolCur(pairData.optDouble("vol_cur")); tickers.add(ticker); } String message = checkNotifiers(tickers, TickersStorage.loadLatestData()); if (message.length() != 0) { NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setSmallIcon(R.drawable.ic_stat_bitcoin_sign) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(message.substring(0, message.length() - 2)); notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build()); } Map<String, Ticker> newData = new HashMap<>(); for (Ticker ticker : tickers) { newData.put(ticker.getPair(), ticker); } TickersStorage.saveData(newData); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers")); } } else { new Handler().post(new Runnable() { @Override public void run() { //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show(); } }); } }
From source file:com.nsqre.insquare.Utilities.PushNotification.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * Manages how the notification will be shown in the notification bar. * @param message GCM message received.//w w w . ja va 2s .c o m */ private void sendNotification(String message, String squareName, String squareId) { Intent intent = new Intent(this, BottomNavActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); SharedPreferences notificationPreferences = getSharedPreferences("NOTIFICATION_MAP", MODE_PRIVATE); int notificationCount = 0; int squareCount = notificationPreferences.getInt("squareCount", 0); if (squareId.equals(notificationPreferences.getString("actualSquare", ""))) { return; } if (!notificationPreferences.contains(squareId)) { notificationPreferences.edit().putInt("squareCount", squareCount + 1).apply(); } notificationPreferences.edit().putInt(squareId, notificationPreferences.getInt(squareId, 0) + 1).apply(); for (String square : notificationPreferences.getAll().keySet()) { if (!"squareCount".equals(square) && !"actualSquare".equals(square)) { notificationCount += notificationPreferences.getInt(square, 0); } } squareCount = notificationPreferences.getInt("squareCount", 0); Log.d(TAG, notificationPreferences.getAll().toString()); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.nsqre_map_pin_empty_inside); notificationBuilder.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)); if (squareCount == 1) { SharedPreferences messagePreferences = getSharedPreferences(squareId, MODE_PRIVATE); intent.putExtra("squareId", squareId); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); messagePreferences.edit().putString(String.valueOf(notificationCount), message).commit(); if (messagePreferences.getAll().size() <= 6) { for (int i = 1; i <= messagePreferences.getAll().keySet().size(); i++) { inboxStyle.addLine(messagePreferences.getString(String.valueOf(i), "")); } } else { for (int i = messagePreferences.getAll().size() - 6; i <= messagePreferences.getAll().keySet() .size(); i++) { inboxStyle.addLine(messagePreferences.getString(String.valueOf(i), "")); } } notificationBuilder.setContentTitle(squareName); notificationBuilder.setStyle(inboxStyle.setBigContentTitle(squareName).setSummaryText("inSquare")); notificationBuilder.setContentText( notificationCount > 1 ? "Hai " + notificationCount + " nuovi messaggi" : message); } else { intent.putExtra("map", 0); intent.removeExtra("squareId"); notificationBuilder.setContentTitle("inSquare"); notificationBuilder .setContentText("Hai " + (notificationCount) + " nuovi messaggi in " + squareCount + " piazze"); } notificationBuilder.setAutoCancel(true); notificationBuilder.setSound(defaultSoundUri); notificationBuilder.setVibrate(new long[] { 300, 300, 300, 300, 300 }); notificationBuilder.setLights(Color.RED, 1000, 3000); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_CANCEL_CURRENT); notificationBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); updateSquares("", "", "update"); SharedPreferences mutePreferences = getSharedPreferences("NOTIFICATION_MUTE_MAP", MODE_PRIVATE); if (mutePreferences.contains(squareId)) { String expireDate = mutePreferences.getString(squareId, ""); long myExpireDate = Long.parseLong(expireDate, 10); if (myExpireDate < (new Date().getTime())) { mutePreferences.edit().remove(squareId).apply(); notificationManager.notify(0, notificationBuilder.build()); } } else { notificationManager.notify(0, notificationBuilder.build()); } }
From source file:com.alexforprog.spareparts.GCM.GcmIntentService.java
private void buildNotification(Intent intent) { PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); String dnd = Global.LoadSharedPref(Global.DNDKey, "DND:1", getApplicationContext()); NotificationCompat.Builder mBuilder = null; if (dnd.equals("DND:1")) { mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.bmw_logo).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setVibrate(new long[] { 1000 }); } else { //(dnd.equals("DND:0")) mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.bmw_logo).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setVibrate(new long[] { 1000 }).setSound(uri); }/* www. j a v a 2 s . c o m*/ mBuilder.setContentIntent(contentIntent); mBuilder.setAutoCancel(true); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.cliqz.browser.gcm.MessageListenerService.java
/** * Create and show a simple notification containing the received GCM message. Does nothing if * the notifications are disabled in the preferences. * * @param title GCM message received.//from w ww . j av a 2s . c om * @param url url */ private void sendNewsNotification(int newType, String title, String url, String country) { if (!preferenceManager.getNewsNotificationEnabled() || country == null || !country.equals(preferenceManager.getCountryChoice().countryCode)) { return; } Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.putExtra(Constants.NOTIFICATION_CLICKED, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Intent deleteIntent = new Intent(this, NotificationDismissedReceiver.class); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, deleteIntent, 0); final Uri uri = Uri.parse(url); final String host = uri.getHost(); final String domain = UrlUtils.getTopDomain(url); final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(title); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification_news).setContentTitle(domain) .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION).setContentText(title).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent).setDeleteIntent(deletePendingIntent) .setStyle(style); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.barelabor.barelabor.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//w w w.jav a2 s . c o m */ private void sendNotification(String repairArrayString, String highCostArrayString, String averageCostArrayString, String lowCostArrayString, String lowPrice, String highPrice, String avgPrice) { // String lowPrice = "0", highPrice = "0", avgPrice = "0"; // try { // JSONArray data = new JSONArray(message); // lowPrice = data.getJSONObject(0).getString("lowCost"); // avgPrice = data.getJSONObject(0).getString("averageCost"); // highPrice = data.getJSONObject(0).getString("highCost"); // } catch (JSONException e) { // e.printStackTrace(); // } Intent intent = new Intent(this, MenuActivity.class); intent.putExtra("low_price", lowPrice); intent.putExtra("high_price", highPrice); intent.putExtra("avg_price", avgPrice); intent.putExtra("repairArrayString", repairArrayString); intent.putExtra("highCostArrayString", highCostArrayString); intent.putExtra("averageCostArrayString", averageCostArrayString); intent.putExtra("lowCostArrayString", lowCostArrayString); intent.putExtra("notification", true); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("BareLabor") .setContentText("The pricing for your printed estimate has arrived").setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.example.prahathessrengasamy.roomie.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//* w ww .j a v a 2 s . c om*/ private void sendNotification(String messageTitle, String messageBody) { Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.i1) //.setLargeIcon(R.mipmap.logos) .setLargeIcon( BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.roomielogo)) .setContentTitle(messageTitle).setContentText(messageBody).setAutoCancel(false).setOngoing(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify((int) System.currentTimeMillis() /* ID of notification */, notificationBuilder.build()); }