List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java
private Notification preAPI16() { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setTicker(title) .setContentText(subtitle).setAutoCancel(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(pendingIntent); return notificationBuilder.build(); }
From source file:com.preguardia.app.notification.MyGcmListenerService.java
private void showMedicNotification(String title, String message, String consultationId) { // Prepare intent which is triggered if the notification is selected Intent intent = new Intent(this, ApproveConsultationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId); PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.MEDIC_REQUEST_CODE, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(2, notificationBuilder.build()); }
From source file:com.nifcloud.mbaas.ncmbfcmplugin.NCMBFirebaseMessagingService.java
public NotificationCompat.Builder notificationSettings(Bundle pushData) { //AndroidManifest?? ApplicationInfo appInfo = null;//from w w w . j a v a2 s .c o m Class startClass = null; String applicationName = null; String activityName = null; String packageName = null; int channelIcon = 0; try { appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); applicationName = getPackageManager() .getApplicationLabel(getPackageManager().getApplicationInfo(getPackageName(), 0)).toString(); activityName = appInfo.packageName + ".UnityPlayerNativeActivity"; packageName = appInfo.packageName; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException(e); } Log.d("Unity", "activityName: " + activityName + "| packageName:" + packageName); //Note FCM //???????? Intent intent = new Intent(this, com.nifcloud.mbaas.ncmbfcmplugin.UnityPlayerActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtras(pushData); PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt(), intent, PendingIntent.FLAG_CANCEL_CURRENT); //pushData?? String message = ""; String title = ""; if (pushData.getString("title") != null) { title = pushData.getString("title"); } else { //title???????? title = applicationName; } if (pushData.getString("message") != null) { message = pushData.getString("message"); } //SmallIconmanifests??????? int userSmallIcon = appInfo.metaData.getInt(SMALL_ICON_KEY); int icon; if (userSmallIcon != 0) { //manifests?????? icon = userSmallIcon; } else { //????? icon = appInfo.icon; } //SmallIcon int smallIconColor = appInfo.metaData.getInt(SMALL_ICON_COLOR_KEY); //Notification? Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, com.nifcloud.mbaas.ncmbfcmplugin.NCMBNotificationUtils.getDefaultChannel()).setSmallIcon(icon)//? .setColor(smallIconColor)//? .setContentTitle(title).setContentText(message).setAutoCancel(true)//???? .setSound(defaultSoundUri)//? .setContentIntent(pendingIntent);//????Activity return notificationBuilder; }
From source file:com.example.khalid.sharektest.Utils.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param dataPayLoad FCM message body received. *///from ww w . j a v a2 s . c o m private void sendNotification(JSONObject dataPayLoad) { try { if (dataPayLoad.get("type").equals("proposal")) { intent = new Intent(this, MyProfile.class); } else if (dataPayLoad.get("type").equals("proposal-reaction")) { intent = new Intent(this, NotificationActivity.class); String stringObject = dataPayLoad.toString(); intent.putExtra("data", stringObject); } else { intent = new Intent(this, HomePage.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.notification_icon2).setContentTitle("Sharek") .setContentText(dataPayLoad.getString("body")).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.owncloud.android.jobs.MediaFoldersDetectionJob.java
private void sendNotification(String contentTitle, String subtitle, Account account, String path, int type) { Context context = getContext(); Intent intent = new Intent(getContext(), SyncedFoldersActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(NotificationJob.KEY_NOTIFICATION_ACCOUNT, account.name); intent.putExtra(KEY_MEDIA_FOLDER_PATH, path); intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type); intent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, true); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NotificationUtils.NOTIFICATION_CHANNEL_GENERAL) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(/*www . j a va 2 s . com*/ BitmapFactory.decodeResource(context.getResources(), R.drawable.notification_icon)) .setColor(ThemeUtils.primaryColor(getContext())).setSubText(account.name) .setContentTitle(contentTitle).setContentText(subtitle) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setAutoCancel(true).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.notify(0, notificationBuilder.build()); } }
From source file:ch.carteggio.provider.sync.NotificationService.java
private void updateUnreadNotification(boolean newMessage) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); CarteggioProviderHelper helper = new CarteggioProviderHelper(this); int unreadCount = helper.getUnreadCount(); if (unreadCount == 0) { mNotificationManager.cancel(INCOMING_NOTIFICATION_ID); } else {//from ww w . ja v a2 s . c om String quantityString = getResources().getQuantityString(R.plurals.notification_new_incoming_messages, unreadCount); NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(String.format(quantityString, unreadCount)) .setSmallIcon(android.R.drawable.stat_notify_chat) .setContentText(getString(R.string.notification_text_new_messages)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notifyBuilder.setContentIntent(resultPendingIntent); if (newMessage) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); long pattern[] = { 1000, 500, 2000 }; if (manager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { notifyBuilder.setSound(uri); notifyBuilder.setVibrate(pattern); } else if (manager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { notifyBuilder.setVibrate(pattern); } } mNotificationManager.notify(INCOMING_NOTIFICATION_ID, notifyBuilder.build()); } }
From source file:com.teamappjobs.appjobs.FCM.MyFirebaseMessagingService.java
private void sendNotification(String titulo, String message, String tag, PendingIntent pendingIntent, int cor, int icone) { Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); long[] v = { 100, 500, 100, 500 }; //Vibrao NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(icone) .setColor(cor).setContentTitle(titulo).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setVibrate(v).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(tag, 0, notificationBuilder.build()); }
From source file:com.brq.wallet.lt.activity.LtMainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _mbwManager = MbwManager.getInstance(this); _ltManager = _mbwManager.getLocalTraderManager(); _viewPager = new ViewPager(this); _viewPager.setId(R.id.pager);/*from w ww .j a v a 2 s. c om*/ setContentView(_viewPager); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // to provide up navigation from actionbar, in case the modern main // activity is not on the stack actionBar.setDisplayHomeAsUpEnabled(true); TabsAdapter tabsAdapter = new TabsAdapter(this, _viewPager); // Add Buy Bitcoin tab _myBuyBitcoinTab = actionBar.newTab(); _myBuyBitcoinTab.setText(getResources().getString(R.string.lt_buy_bitcoin_tab)); tabsAdapter.addTab(_myBuyBitcoinTab, AdSearchFragment.class, AdSearchFragment.createArgs(true)); // Add Sell Bitcoin tab _mySellBitcoinTab = actionBar.newTab(); _mySellBitcoinTab.setText(getResources().getString(R.string.lt_sell_bitcoin_tab)); tabsAdapter.addTab(_mySellBitcoinTab, AdSearchFragment.class, AdSearchFragment.createArgs(false)); // Add Active Trades tab _myActiveTradesTab = actionBar.newTab(); _myActiveTradesTab.setText(getResources().getString(R.string.lt_active_trades_tab)); tabsAdapter.addTab(_myActiveTradesTab, ActiveTradesFragment.class, null); // Add Historic Trades tab _myTradeHistoryTab = actionBar.newTab(); _myTradeHistoryTab.setText(getResources().getString(R.string.lt_trade_history_tab)); tabsAdapter.addTab(_myTradeHistoryTab, TradeHistoryFragment.class, null); // Add Ads tab _myAdsTab = actionBar.newTab(); _myAdsTab.setText(getResources().getString(R.string.lt_my_ads_tab)); _myAdsTab.setTag(tabsAdapter.getCount()); tabsAdapter.addTab(_myAdsTab, AdsFragment.class, null); // Add Trader Info tab _myTraderInfoTab = actionBar.newTab(); _myTraderInfoTab.setText(getResources().getString(R.string.lt_my_trader_info_tab)); _myTraderInfoTab.setTag(tabsAdapter.getCount()); tabsAdapter.addTab(_myTraderInfoTab, MyInfoFragment.class, null); // Load the tab to select from intent TAB_TYPE tabToSelect = TAB_TYPE.values()[getIntent().getIntExtra(TAB_TO_SELECT, TAB_TYPE.DEFAULT.ordinal())]; actionBar.selectTab(enumToTab(tabToSelect)); _updateSound = RingtoneManager.getRingtone(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); // Load saved state if (savedInstanceState != null) { _hasWelcomed = savedInstanceState.getBoolean("hasWelcomed", false); } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;// w w w. jav a 2 s . c o m } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else { resultIntent = new Intent(context, MaterialMainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
From source file:com.example.bibliotecauclm.net.ActualizadorListaLibros.java
/** * Este mtodo es el encargado de revisar la lista de libros recuperados * por si alguno est pasado de fecha, le falta un da o debe ser renovado hoy. * //from ww w . ja v a 2 s. c o m * @param res */ private void lanzarNotificacionRenovar(List<Libro> res) { int renovables = 0, expiranHoy = 0, pasadosDeFecha = 0; for (Libro l : res) { int estado = Utiles.estadoLibro(l); if (estado == -1) ; else if (estado == 0) { pasadosDeFecha++; } else if (estado == 1) { expiranHoy++; } else if (estado == 2) { renovables++; } } if ((renovables != 0) || (expiranHoy != 0) || (pasadosDeFecha != 0)) { Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(contexto) .setSmallIcon(R.drawable.ic_stat_logo) .setLargeIcon((((BitmapDrawable) contexto.getResources().getDrawable(R.drawable.ic_launcher)) .getBitmap())) .setContentTitle("Estado de los libros...") .setContentText(pasadosDeFecha + " Pasados " + expiranHoy + " Hoy " + renovables + " Maana") .setTicker("Estado de los libros...").setSound(notificationSound).setAutoCancel(true); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String[] events = new String[3]; events[0] = pasadosDeFecha + " libros pasados"; events[1] = expiranHoy + " a devolver hoy"; events[2] = renovables + " a devolver maana"; inboxStyle.setBigContentTitle("Estado de los libros..."); for (int i = 0; i < events.length; i++) { inboxStyle.addLine(events[i]); } mBuilder.setStyle(inboxStyle); Intent inten = new Intent(contexto, ActivityLibros.class); PendingIntent cont = PendingIntent.getActivity(contexto, 0, inten, 0); mBuilder.setContentIntent(cont); this.mNotificationManager.notify(2, mBuilder.build()); } }