Example usage for android.media RingtoneManager getDefaultUri

List of usage examples for android.media RingtoneManager getDefaultUri

Introduction

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

Prototype

public static Uri getDefaultUri(int type) 

Source Link

Document

Returns the Uri for the default ringtone of a particular type.

Usage

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.//  w w  w .  j a  v a2  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.//from w  ww .ja  v a2s .  c o m
 */
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;/*w  ww .ja va2 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   ww w  .  j  av a  2  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.
 * //  w w w .j  av  a 2s . c  o m
 * @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.//  w w  w.  j a va2s  .co 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  w  w  w .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());
}

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// w  ww  . j a v a  2  s  . 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 w  w .j  ava2s .  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());
}