Example usage for android.media RingtoneManager TYPE_NOTIFICATION

List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION

Introduction

In this page you can find the example usage for android.media RingtoneManager TYPE_NOTIFICATION.

Prototype

int TYPE_NOTIFICATION

To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.

Click Source Link

Document

Type that refers to sounds that are used for notifications.

Usage

From source file:net.olejon.mdapp.MessageIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    final Context mContext = this;

    final MyTools mTools = new MyTools(mContext);

    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    int projectVersionCode = mTools.getProjectVersionCode();

    String device = mTools.getDevice();

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website_uri) + "api/1/message/?version_code=" + projectVersionCode
                    + "&device=" + device,
            new Response.Listener<JSONObject>() {
                @SuppressLint("InlinedApi")
                @Override//from  w  w w .  j av  a 2s  .c  o m
                public void onResponse(JSONObject response) {
                    try {
                        final long id = response.getLong("id");
                        final String title = response.getString("title");
                        final String message = response.getString("message");
                        final String bigMessage = response.getString("big_message");
                        final String button = response.getString("button");
                        final String uri = response.getString("uri");

                        final long lastId = mTools.getSharedPreferencesLong("MESSAGE_LAST_ID");

                        mTools.setSharedPreferencesLong("MESSAGE_LAST_ID", id);

                        if (lastId != 0 && id != lastId) {
                            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()).setAutoCancel(true)
                                    .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(message).setContentTitle(title)
                                    .setContentText(message)
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMessage));

                            if (!uri.equals("")) {
                                Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                                PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0,
                                        launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                                notificationBuilder.setContentIntent(launchPendingIntent).addAction(
                                        R.drawable.ic_local_hospital_white_24dp, button, launchPendingIntent);
                            }

                            notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
                        }
                    } catch (Exception e) {
                        Log.e("MessageIntentService", Log.getStackTraceString(e));
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("MessageIntentService", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);
}

From source file:com.cc.basefunction.service.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from w ww  .ja v a  2s .c  o  m
private void sendNotification(String messageBody) {
    Intent intentClick = new Intent(this, NotificationBroadCast.class);
    intentClick.setAction("BASEFUNCTION_NOTIFICATION_CLICK");
    intentClick.putExtra("message", messageBody);
    PendingIntent pendingIntentClick = PendingIntent.getBroadcast(this, 0, intentClick,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent intentCancel = new Intent(this, NotificationBroadCast.class);
    intentCancel.setAction("BASEFUNCTION_NOTIFICATION_CANCEL");
    intentCancel.putExtra("message", messageBody);
    PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 0, intentCancel,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setSmallIcon(R.drawable.notification_iocn);
        notificationBuilder.setColor(getResources().getColor(R.color.blue_B0E0E6));
    } else {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    }
    notificationBuilder.setContentTitle("BaseFunction Notification").setContentText(messageBody)
            .setSound(defaultSoundUri).setContentIntent(pendingIntentClick)
            .setDeleteIntent(pendingIntentCancel);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(10086 /* ID of notification */, notificationBuilder.build());
}

From source file:com.perfilyev.vkmessengerlite.MessagingService.java

NotificationCompat.Builder provideBuilder(long peerId) {
    PendingIntent contentIntent = createPendingIntent();

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    List<ChatItem.NotificationInfoPeer> notificationInfoList = database
            .createQuery(ChatItem.TABLE_NAME, ChatItem.NOTIFICATION_FOR_PEER, String.valueOf(peerId))
            .mapToList(ChatItem.NOTIFICATION_INFO_PEER_ROW_MAPPER::map).toBlocking().first();

    NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle(USER_DISPLAY_NAME);

    String groupKey = null;/* w w  w .  j a  v a 2 s .c o m*/
    int count = 0;

    for (ChatItem.NotificationInfoPeer notificationInfo : notificationInfoList) {
        style.addMessage(notificationInfo.body(), notificationInfo.date(), notificationInfo.fullName());
        if (groupKey == null) {
            groupKey = notificationInfo.fullName();
        }
        if (peerId > 2000000000) {
            style.setConversationTitle(notificationInfo.peerName());
            groupKey = notificationInfo.peerName();
        }
        count++;
    }
    NotificationCompat.Action replyAction = createReplyAction(peerId, contentIntent);

    NotificationCompat.Builder builder = createBuilder(defaultSoundUri, contentIntent);
    return builder.setStyle(style).addAction(replyAction).setGroup(groupKey).setGroupSummary(true)
            .setSubText(String.format(Locale.getDefault(), "Unread: %s", count));
}

From source file:com.nicolacimmino.expensestracker.tracker.data_sync.GcmIntentService.java

private void showExpensesUpdatedNotification() {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, ExpensesListActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(getResources().getString(R.string.notification_data_changed)))
            .setContentText(getResources().getString(R.string.notification_data_changed)).setAutoCancel(true)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLights(Color.rgb(219, 70, 0), 700, 1000).setOnlyAlertOnce(true);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(EXPENSES_UPDATED_NOTIFICATION_ID, mBuilder.build());
}

From source file:com.phonegap.Notification.java

/**
 * Beep plays the default notification ringtone.
 * //from   w ww  .java  2 s .  com
 * @param count         Number of times to play notification
 */
public void beep(long count) {
    Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);

    // If phone is not set to silent mode
    if (notification != null) {
        for (long i = 0; i < count; ++i) {
            notification.play();
            long timeout = 5000;
            while (notification.isPlaying() && (timeout > 0)) {
                timeout = timeout - 100;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
        }
    }
}

From source file:com.example.petri.myapplication.GCMMessageListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// www  .  java2s  .co m
 */
private void sendNotification(String message, int from_id) {
    Intent intent = new Intent(this, ChatActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("chat_id", from_id);
    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_icon).setContentTitle("GCM Message").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.botree.botree911_client.notification.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w  ww .j a  va 2s. com*/
private void sendNotification(String title, String messageBody) {
    int count = PreferenceUtility.getNoticationCount(MyFirebaseMessagingService.this);
    PreferenceUtility.saveNotificationCount(MyFirebaseMessagingService.this, (count + 1));
    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);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title);
    bigTextStyle.bigText(messageBody);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
        notificationBuilder.setColor(ResourcesCompat.getColor(getResources(), R.color.colorGreenLight, null));
    } else {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    }

    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(messageBody);
    notificationBuilder.setStyle(bigTextStyle);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setSound(defaultSoundUri);
    notificationBuilder.setContentIntent(pendingIntent);

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

    notificationManager.notify(count /* ID of notification */, notificationBuilder.build());
}

From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*w  w  w. j av  a2 s . c  o m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, GpsMainActivity.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.circle_green).setContentTitle(getString(R.string.gcmClientGcmMsg))
            .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.neatier.shell.notification.FCMListenerService.java

/**
 * Create and show a simple notification containing the received FCM remoteMessage.
 *
 * @param remoteMessage FCM remoteMessage body received.
 *///  w w w  . j ava 2  s  .  c om
private void sendNotification(RemoteMessage remoteMessage) {
    RemoteMessage.Notification noti = remoteMessage.getNotification();
    KeyValuePairs<String, String> data = new KeyValuePairs<>();

    String title = getString(R.string.app_name);
    String message = getString(R.string.fcm_message_default);
    StringBuffer contentText = new StringBuffer();
    if (noti != null) {
        title = TextUtils.isEmpty(noti.getTitle()) ? getString(R.string.app_name) : noti.getTitle();
        contentText.append(
                TextUtils.isEmpty(noti.getBody()) ? getString(R.string.fcm_message_default) : noti.getBody());
    }
    if (remoteMessage.getData() != null) {
        data.putAll(remoteMessage.getData());
        title = data.getOrDefault("title", getString(R.string.app_name));
        contentText.append(data.getOrDefault("message", getString(R.string.fcm_message_default)));
    }
    Context context = this;
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = (int) (System.currentTimeMillis() & 0xfffffff);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack
    //stackBuilder.addParentStack(NotificationActivity.class);
    stackBuilder.addNextIntentWithParentStack(new Intent(context, MainActivity.class));
    stackBuilder.addNextIntent(intent);
    // Adds the Intent to the top of the stack
    //stackBuilder.addNextIntent(intent);
    // Gets a PendingIntent containing the entire back stack
    //Need to set PendingIntent.FLAG_UPDATE_CURRENT to work with the starting intent.
    //See issue: http://goo.gl/lJrMNg
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //PendingIntent resultPendingIntent =
    //      stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_neat_logo).setContentTitle(title).setContentText(contentText.toString())
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(resultPendingIntent)
            .setDefaults(Notification.DEFAULT_VIBRATE);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(requestCode, notificationBuilder.build());
}

From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w w  w  . j a v  a 2  s  .c o  m*/
 */
private void sendNotification(String message) {
    Activity currentAct = UnityPlayer.currentActivity;
    Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class;
    Intent intent = new Intent(this, activityToOpen);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1);
        if (notificationIcon == -1) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }
        int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
        if (notificationLargeIcon == -1) {
            Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
            return;
        }

        String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
        if (pushNotifName == null) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }

        if (notifManager == null)
            notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance);
            channel.setDescription("CotC Channel");
            notifManager.createNotificationChannel(channel);
            notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel");
        } else
            notificationBuilder = new NotificationCompat.Builder(this);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH);
        if (notificationLargeIcon != -1)
            notificationBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

        notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
    } catch (Exception e) {
        Log.w(TAG, "Failed to handle push notification", e);
    }
}