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:com.iovirta.iot_kamera_sovellus.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///  w  w w  . j  av a2 s. co  m
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, mediaView.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("Iot Cam Demo")
            .setContentText("Liikett havaittu!").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.android.talkbacktests.testsession.NotificationTest.java

private void showTickerNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(android.R.drawable.stat_notify_more).setAutoCancel(true)
            .setContentTitle(getString(R.string.ticker_notification_title))
            .setContentText(getString(R.string.ticker_notification_text))
            .setTicker(getString(R.string.ticker_notification_ticker))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build());
}

From source file:com.app.ntuc.notifs.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w ww  .  j av  a 2  s  .  c  o m*/
 */
private void sendNotification(String body, String title, Bundle bundle) {
    Intent intent = new Intent(this, MainActivity2_.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(bundle.toString());
    bigText.setBigContentTitle(body);
    bigText.setSummaryText(title);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    notificationBuilder.setContentTitle(body).setContentText(title);

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

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

From source file:com.trams.azit.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  w  w . java  2 s .  c  om
 */
private void sendNotification(String message, String code) {
    Intent intent;
    if (getSharedPreferences("Azit", MODE_PRIVATE).getString("login", "").equals("false")
            && !Constants.IS_LOGIN) {
        //?? ?  ?  ??
        intent = new Intent(this, LoginActivity_.class);
    } else {
        //??? ?
        int intCode = Integer.parseInt(code);
        switch (intCode) {
        case 201:
            intent = new Intent(this, MyMessage.class);
            break;
        case 401:
            intent = new Intent(this, MentoMainActivity.class);
            intent.putExtra("position", 2);
            break;
        case 402:
            intent = new Intent(this, MyPointActivity.class);
            break;
        case 403:
            intent = new Intent(this, Mento_Act.class);
            break;
        case 404:
            intent = new Intent(this, MentoMainActivity.class);
            break;
        default:
            intent = new Intent(this, LoginActivity_.class);
            break;
        }
    }
    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.app_icon).setContentTitle(getResources().getString(R.string.app_name))
            .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.mariogrip.octodroid.service.java

protected void startPrintService() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int savemode = 4000;
    if (prefs.getBoolean("battery", false)) {
        savemode = 20000;/*ww  w .j  a v a 2 s.  com*/
    }
    final boolean notef = prefs.getBoolean("stick", true);
    final int id = 1;
    Log.d("OctoDroid Service", "StartprintService");

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle("OctoDroid").setContentText("Printing").setOngoing(true)
            .setSmallIcon(R.drawable.octodroid_smal);
    if (notef && !notefaRunning) {
        mNotifyManager.notify(id, mBuilder.build());
        notefaRunning = true;
    }

    timerTask2 = new TimerTask() {
        @Override
        public void run() {
            Log.d("OctoDroid Service", "startPrintService timertask");
            try {
                util_decode.decodeConnections();
                util_decode.decodeJob();
                complete = memory.job.progress.completion;
            } catch (Exception e) {
                complete = 0;
            }
            if (!memory.connection.current.getState().equals("Printing")) {
                Log.d("OctoDroid Service", "startPrintService stopping");
                mainActivity.printing = false;
                notefaRunning = false;
                mNotifyManager.cancel(id);
                Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                mBuilder.setContentText("Print complete").setContentTitle("OctoDroid").setSound(soundUri)
                        .setSmallIcon(R.drawable.octodroid_smal).setOngoing(false).setProgress(0, 0, false);
                mNotifyManager.notify(id, mBuilder.build());
                timerTask2.cancel();
                runner();
                return;
            }
            Log.d("OctoDroid Service", "startPrintService Notify" + complete);
            if (notef) {
                mBuilder.setProgress(100, (int) complete, false)
                        .setContentText("Printing (" + (int) complete + "%)");
                mNotifyManager.notify(id, mBuilder.build());
            }
        }
    };
    timer2.schedule(timerTask2, 0, savemode);
}

From source file:com.example.demoflavius.GcmIntentService.java

private void sendNotification(String msg) {
    try {/*from w  ww . j  ava2  s .  c  om*/
        JSONObject myJson = new JSONObject(msg);
        String content = myJson.getString("content");
        String fromId = myJson.getString("fromId");
        String fromPicture = myJson.getString("fromPicture");
        String fromName = myJson.getString("fromName");

        if (MyApplication.applicationIsActive == false) {
            mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
            Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

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

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ninja).setContentTitle(content)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(fromName))
                    .setSound(notificationSound).setContentText(content);

            mBuilder.setContentIntent(contentIntent);
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        } else {
            Message message = new Message();
            message.setContent(content);
            message.setFromId(fromId);
            message.setFromName(fromName);
            message.setFromPicture(fromPicture);

            MessagingService.addMessage(fromId, content, true);
            MyApplication.snd.playSound(R.raw.chat_sound);
            if (fromId.equals(ChatPageFragment.currentCustomerIdITalkTo) == false) {
                NotificationService.showInfoCrouton(String.format("%s said: %s", fromName, content), fromId);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        NotificationService.showDebugCrouton("failed at sendNotification!");
    }
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Beep plays the default notification ringtone.
 * //from   w  w w .j  a v  a  2 s. c om
 * @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.cordova.getActivity().getBaseContext(), 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.fitc.dooropener.lib.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param status GCM message received.//from   ww w  . ja va 2  s . c o  m
 */
private void sendNotification(GcmDataPayload status) {

    /**
     * This code should find launcher activity of app using this librbary and set it as the what gets launched
     */
    Intent intent = null;
    final PackageManager packageManager = getPackageManager();
    Log.i(TAG, "PACKAGE NAME " + getPackageName());

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);

    for (final ResolveInfo resolveInfo : appList) {
        if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)
        {
            intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            break;
        }
    }
    PendingIntent pendingIntent = null;
    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        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(getResources().getString(R.string.notif_content_title))
            .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri);

    if (pendingIntent != null) {
        notificationBuilder.setContentIntent(pendingIntent);
    }

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

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

From source file:com.dishcuss.foodie.hub.GCM.MyGcmListenerService.java

private void sendNotification(String message, String title, String type, int id) {

    Intent intent = new Intent(this, HomeActivity.class);

    if (type.equals("Credit")) {
        intent = new Intent(this, MyWalletActivity.class);
    }/*from   www.j a  v  a 2 s.c om*/

    if (type.equals("User")) {
        if (id != 0) {
            intent = new Intent(this, ProfilesDetailActivity.class);
            intent.putExtra("UserID", id);
        }
    }

    if (type.equals("Post")) {
        intent = new Intent(this, NotificationClickPostDetail.class);
        intent.putExtra("TypeID", id);
        intent.putExtra("Type", "Post");
    }

    if (type.equals("Review")) {
        intent = new Intent(this, NotificationClickPostDetail.class);
        intent.putExtra("TypeID", id);
        intent.putExtra("Type", "Review");
    }

    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.logo).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.mobirix.battlefieldcommander.activity.BillingNativeActivity.java

public void sendNotification(int id, String title, String message) {
    Intent intent = new Intent(this, BillingNativeActivity.class);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Resources res = this.getResources();
    int icon = res.getIdentifier("ic_stat_ic_notification", "drawable", this.getPackageName());

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon) //todo
            .setContentTitle(title).setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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