List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.sopinet.trazeo.app.chat.GcmIntentService.java
public void launchNotification(Message message, Group group, String type, boolean showMessage) { Intent chatIntent = new Intent("com.sopinet.trazeo.app.chatmessage"); chatIntent.putExtra("groupId", group.id); chatIntent.putExtra("username", message.username); chatIntent.putExtra("time", message.time); chatIntent.putExtra("longId", message.getId()); sendBroadcast(chatIntent);/*from w w w.java 2 s . c om*/ // If chat is not on foreground (visible), launch notifications if (group.chat != null && group.chat.visibility == 0) { Intent i = new Intent(this, ChatActivity_.class); i.putExtra("groupId", group.id); i.putExtra("fromNotification", true); String msg; switch (message.type) { case Message.RECEIVED: msg = "Nuevo mensaje en: " + group.name; break; default: msg = message.text; break; } NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(type.equals(TEXT) ? R.drawable.mascota_arrow : R.drawable.mascota_arrow2) .setContentTitle(getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFF0000FF, 100, 3000) .setContentText(msg).setAutoCancel(true); SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE); //String notifications = sharedPreferences.getString("status_notifications", "on"); String sounds = sharedPreferences.getString("sounds", "on"); if (sounds.equals("on")) { mBuilder.setSound(alarmSound); } mBuilder.setContentIntent(contentIntent); switch (type) { case TEXT: if (sharedPreferences.getBoolean("chatsNotification", true)) mNotificationManager.notify(notificationId, mBuilder.build()); break; case RIDE_STARTED: case RIDE_FINISHED: if (sharedPreferences.getBoolean("RaidInOutNotification", true) && showMessage) mNotificationManager.notify(notificationId, mBuilder.build()); break; case CHILD_IN: case CHILD_OUT: if (sharedPreferences.getBoolean("childInOutNotification", true)) mNotificationManager.notify(notificationId, mBuilder.build()); break; } } }
From source file:com.example.mapdemo.MyLocationDemoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { instance = this; super.onCreate(savedInstanceState); setContentView(R.layout.my_location_demo); ButterKnife.bind(this); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map); mapFragment.getMapAsync(this); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return;/*from w w w.ja v a 2 s . c o m*/ } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new PositionListener()); alarm = RingtoneManager.getRingtone(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)); handler.postDelayed(new Runnable() { @Override public void run() { createDialogForProgrammedStop(); handler.postDelayed(this, Constants.TIME); } }, Constants.TIME); }
From source file:com.amazon.rvspeedtest.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Uri uriSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("Alexa Phone Finder") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setSound(uriSound) .setVibrate(new long[] { 3000, 1000, 3000, 1000, 3000, 1000, 3000 }) .setLights(Color.RED, 3000, 3000).setCategory(Notification.CATEGORY_ALARM); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.handshake.notifications.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. *///from w w w . ja va2 s. co m private void sendNotification(final Bundle data, long userId, boolean isContact) { Intent intent; if (userId == 0) { intent = new Intent(this, MainActivity.class); } else if (isContact) { intent = new Intent(this, ContactUserProfileActivity.class); } else { intent = new Intent(this, GenericUserProfileActivity.class); } intent.putExtra("userId", userId); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 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.ic_stat_ic_notification).setContentTitle("Handshake") .setContentText(data.getString("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:cs460.grouple.grouple.GcmIntentService.java
private void sendNotification(String msg) { updateMyActivity(this);// crash seems RECEIVER be here Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_MESSAGE.toString())) { Intent notificationIntent = new Intent(this, EntityMessagesActivity.class); if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString())) { notificationIntent.putExtra("CONTENT_TYPE", "GROUP"); notificationIntent.putExtra("GID", RECEIVER); Group g = new Group(Integer.parseInt(RECEIVER)); g.fetchGroupInfo();//from w w w . j a v a 2 s . co m GLOBAL.setGroupBuffer(g); } else { notificationIntent.putExtra("CONTENT_TYPE", "EVENT"); notificationIntent.putExtra("EID", RECEIVER); Event e = new Event(Integer.parseInt(RECEIVER)); e.fetchEventInfo(); GLOBAL.setEventBuffer(e); } notificationIntent.putExtra("email", SENDER); notificationIntent.putExtra("name", NAME); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentTitle(NAME) .setStyle(new NotificationCompat.BigTextStyle() // .bigText(msg)) .bigText(SENDER_FIRST + " " + SENDER_LAST + ": " + msg)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.USER_MESSAGE.toString())) { Intent notificationIntent = new Intent(getApplicationContext(), MessagesActivity.class); notificationIntent.putExtra("sender", SENDER); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("receiver", RECEIVER); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle(SENDER_FIRST + " " + SENDER_LAST) .setStyle(new NotificationCompat.BigTextStyle() // .bigText(msg)) .bigText(msg)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.FRIEND_REQUEST.toString())) { // Send friend request. Intent notificationIntent = new Intent(getApplicationContext(), ListActivity.class); notificationIntent.putExtra("email", GLOBAL.getCurrentUser().getEmail()); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("content", CONTENT_TYPE.FRIEND_REQUEST.toString()); GLOBAL.getCurrentUser().fetchFriendRequests(); GLOBAL.getCurrentUser().fetchUserInfo(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle("New friend request from " + SENDER_FIRST + " " + SENDER_LAST + "!") .setStyle(new NotificationCompat.BigTextStyle().bigText(SENDER_FIRST + " " + SENDER_LAST)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.GROUP_INVITE.toString())) { // Send friend request. Intent notificationIntent = new Intent(getApplicationContext(), ListActivity.class); notificationIntent.putExtra("email", GLOBAL.getCurrentUser().getEmail()); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("content", "GROUPS_INVITES"); GLOBAL.getCurrentUser().fetchFriendRequests(); GLOBAL.getCurrentUser().fetchUserInfo(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle( "New group invite to " + NAME + " from " + SENDER_FIRST + " " + SENDER_LAST + "!") .setStyle(new NotificationCompat.BigTextStyle().bigText(SENDER_FIRST + " " + SENDER_LAST)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:com.hmlee.chat.chatclient.fcm.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from ww w . jav a 2 s.c o m private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.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.mipmap.contact).setContentTitle("FCM Message").setContentText(messageBody) .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.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.profile_custom_secondary); getSupportActionBar().setDisplayHomeAsUpEnabled(true); dbAdapter = new DbAdapter(this); if (getIntent().hasExtra("profile")) { profile = getIntent().getParcelableExtra("profile"); } else {//from w w w . j a va 2s . c o m profile = new SecondaryProfile(); profile.setEnabled(true); profile.setVibrate(true); profile.setLed(true); } nameField = (EditText) findViewById(R.id.nameField); nameField.setText(profile.getName()); nameField.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { validateName(); if (tagField.getText().length() == 0) { tagField.setText(nameField.getText().toString().toLowerCase(Locale.getDefault()) .replaceAll("\\s", "")); validateTag(); } } } }); tagField = (EditText) findViewById(R.id.tagField); tagField.setText(profile.getTag()); tagField.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { validateTag(); } } }); tagRequestButton = (ImageButton) findViewById(R.id.tagRequestButton); tagRequestButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SherlockDialogFragment newFragment = new RequestTagsDialogFragment(); newFragment.show(getSupportFragmentManager(), null); } }); unconnectedOnlyCheckBox = (CheckBox) findViewById(R.id.unconnectedOnlyCheckBox); unconnectedOnlyCheckBox.setChecked(profile.isUnconnectedOnly()); ringtoneSelector = (Button) findViewById(R.id.ringtoneSelector); ringtoneSelector.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, getRingtoneUri(profile.getRingtone())); startActivityForResult(intent, REQUEST_CODE_RINGTONE_PICKER); } }); vibrateCheckBox = (CheckBox) findViewById(R.id.vibrateCheckBox); vibrateCheckBox.setChecked(profile.isVibrate()); checkForVibrator(); lightsCheckBox = (CheckBox) findViewById(R.id.lightsCheckBox); lightsCheckBox.setChecked(profile.isLed()); updateRingtoneSelector(); }
From source file:com.example.dhaejong.acp2.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* ww w . jav a 2 s . co m*/ */ private void sendNotification(String message, String title) { Intent intent = new Intent(this, Main2Activity.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.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.vis.GcmIntentService.java
private void sendNotification(String notificationMessage) { try {//from ww w . j ava2 s.c om mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Gson gson = new Gson(); NotificationMessage notification = gson.fromJson(notificationMessage, NotificationMessage.class); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("NOTIFICATION", notificationMessage); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Video in Short").setSound(alarmSound) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())) .setContentText(notification.getMessage()); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Tracker t = ((Analytics) getApplication()).getDefaultTracker(); // Build and send an Event. t.send(new HitBuilders.EventBuilder().setCategory("GCM").setAction("Message") .setLabel("Message recieved").build()); } catch (JsonSyntaxException e) { e.printStackTrace(); } }
From source file:de.azapps.mirakel.reminders.ReminderAlarm.java
private static void createNotification(final Context context, final Task task) { Log.w(TAG, task.getName());/*from www .ja va 2 s . co m*/ final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Optional<Class<?>> main = Helpers.getMainActivity(); if (!main.isPresent()) { return; } final Intent openIntent = new Intent(context, main.get()); final Bundle withTask = new Bundle(); withTask.putParcelable(DefinitionsHelper.EXTRA_TASK, task); openIntent.setAction(DefinitionsHelper.SHOW_TASK_REMINDER); openIntent.putExtra(DefinitionsHelper.EXTRA_TASK_REMINDER, task); openIntent.putExtra(String.valueOf(task.getId()), task.getId()); openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pOpenIntent = PendingIntent.getActivity(context, 0, openIntent, 0); final Intent doneIntent = new Intent(context, TaskService.class); doneIntent.setAction(TaskService.TASK_DONE); doneIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask); doneIntent.putExtra(String.valueOf(task.getId()), task.getId()); doneIntent.setData(Uri.parse(doneIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pDoneIntent = PendingIntent.getService(context, 0, doneIntent, 0); final Intent laterIntent = new Intent(context, TaskService.class); laterIntent.setAction(TaskService.TASK_LATER); laterIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask); laterIntent.putExtra(String.valueOf(task.getId()), task.getId()); laterIntent.setData(Uri.parse(laterIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pLaterIntent = PendingIntent.getService(context, 0, laterIntent, 0); final boolean persistent = MirakelCommonPreferences.usePersistentReminders(); // Build Notification final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.reminder_notification_title, task.getName())) .setContentText(task.getContent()).setSmallIcon(R.drawable.ic_mirakel) .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, context)).setContentIntent(pOpenIntent) .setPriority(NotificationCompat.PRIORITY_HIGH).setLights(Color.BLUE, 1500, 300) .setOngoing(persistent).setDefaults(Notification.DEFAULT_VIBRATE) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .addAction(R.drawable.ic_checkmark_holo_light, context.getString(R.string.reminder_notification_done), pDoneIntent) .addAction(android.R.drawable.ic_menu_close_clear_cancel, context.getString(R.string.reminder_notification_later), pLaterIntent); final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); final String priority = ((task.getPriority() > 0) ? ("+" + task.getPriority()) : String.valueOf(task.getPriority())); final CharSequence due; if (!task.getDue().isPresent()) { due = context.getString(R.string.no_date); } else { due = DateTimeHelper.formatDate(context, task.getDue()); } inboxStyle.addLine(context.getString(R.string.reminder_notification_list, task.getList().getName())); inboxStyle.addLine(context.getString(R.string.reminder_notification_priority, priority)); inboxStyle.addLine(context.getString(R.string.reminder_notification_due, due)); builder.setStyle(inboxStyle); // Build notification if (!allReminders.contains(task.getId())) { allReminders.add(task.getId()); nm.notify(DefinitionsHelper.NOTIF_REMINDER + (int) task.getId(), builder.build()); } }