当前位置: 首页>>代码示例>>Java>>正文


Java RingtoneManager类代码示例

本文整理汇总了Java中android.media.RingtoneManager的典型用法代码示例。如果您正苦于以下问题:Java RingtoneManager类的具体用法?Java RingtoneManager怎么用?Java RingtoneManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RingtoneManager类属于android.media包,在下文中一共展示了RingtoneManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setPowerNotificationRingtone

import android.media.RingtoneManager; //导入依赖的package包/类
private void setPowerNotificationRingtone(Intent intent) {
    final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

    final String toneName;
    final String toneUriPath;

    if ( uri != null ) {
        final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri);
        toneName = ringtone.getTitle(getActivity());
        toneUriPath = uri.toString();
    } else {
        // silent
        toneName = getString(R.string.power_notifications_ringtone_silent);
        toneUriPath = POWER_NOTIFICATIONS_SILENT_URI;
    }

    mPowerSoundsRingtone.setSummary(toneName);
    CMSettings.Global.putString(getContentResolver(),
            CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath);
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:21,代码来源:OtherSoundSettings.java

示例2: showUpdateNotAvailableNotification

import android.media.RingtoneManager; //导入依赖的package包/类
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentIntent(contentIntent)
            .setContentTitle(title)
            .setContentText(content)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setSmallIcon(smallIconResourceId)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setOnlyAlertOnce(true)
            .setAutoCancel(true);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:UtilsDisplay.java

示例3: sendNotification

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, QuakeActivity.class);//**The activity that you want to open when the notification is clicked
    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_error_outline_white_24dp)
            .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());
}
 
开发者ID:rahul051296,项目名称:quake-alert-android-app,代码行数:26,代码来源:MyFirebaseMessagingService.java

示例4: handleDataReceived

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Handles incoming data events from the mesh - toasts the contents of the data.
 *
 * @param e event object from mesh
 */
private void handleDataReceived(MeshManager.RightMeshEvent e) {
    final MeshManager.DataReceivedEvent event = (MeshManager.DataReceivedEvent) e;

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Toast data contents.
            String message = new String(event.data);
            Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();

            // Play a notification.
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(MainActivity.this, notification);
            r.play();
        }
    });
}
 
开发者ID:RightMesh,项目名称:HelloMesh,代码行数:23,代码来源:MainActivity.java

示例5: showNotification

import android.media.RingtoneManager; //导入依赖的package包/类
public NotificationCompat.Builder showNotification() {

            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            notificationId = (int) new Date().getTime();
            mNotifyManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
            mBuilder = new NotificationCompat.Builder(getActivity());
            mBuilder.setContentTitle("Sending mail to " + this.company.getCompanyName())
                    .setContentText("Sending...")
                    .setSound(defaultSoundUri)
                    .setSmallIcon(R.drawable.ic_stat_name);

            mBuilder.setProgress(100, 100, true);
            // Displays the progress bar for the first time.
            mNotifyManager.notify(notificationId, mBuilder.build());

            return mBuilder;
        }
 
开发者ID:othreecodes,项目名称:Quicksend,代码行数:18,代码来源:HomeFragment.java

示例6: beep

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Beep plays the default notification ringtone.
 *
 * @param count     Number of times to play notification
 */
public void beep(final long count) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone notification = RingtoneManager.getRingtone(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) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            }
        }
    });
}
 
开发者ID:Andy-Ta,项目名称:COB,代码行数:30,代码来源:Notification.java

示例7: showUpdateAvailableNotification

import android.media.RingtoneManager; //导入依赖的package包/类
static void showUpdateAvailableNotification(Context context, String title, String content, UpdateFrom updateFrom, URL apk, int smallIconResourceId) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);
    PendingIntent pendingIntentUpdate = PendingIntent.getActivity(context, 0, UtilsLibrary.intentToUpdate(context, updateFrom, apk), PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentIntent(contentIntent)
            .setContentTitle(title)
            .setContentText(content)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setSmallIcon(smallIconResourceId)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setOnlyAlertOnce(true)
            .setAutoCancel(true)
            .addAction(R.drawable.ic_system_update_white_24dp, context.getResources().getString(R.string.appupdater_btn_update), pendingIntentUpdate);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:UtilsDisplay.java

示例8: getRingtoneName

import android.media.RingtoneManager; //导入依赖的package包/类
@NonNull public static String getRingtoneName(@NonNull Context context, @Nullable Uri uri) {
    String title = context.getString(R.string.sound_chooser_summary);
    if (uri != null) {
        Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
        if (ringtone != null) {
            return ringtone.getTitle(context);
        } else {
            try (Cursor cur = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?",
                    new String[]{uri.getLastPathSegment()}, null)) {
                if (cur != null) {
                    title = cur.getString(1);
                    if (InputHelper.isEmpty(title)) {
                        title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE));
                    }
                }
            } catch (Exception ignored) {}
        }
    }
    return title;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:22,代码来源:FileHelper.java

示例9: displayNotification

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Muestra que ha habido una nueva notificación
 * @param notification
 * @param data
 */
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("notificacion","notificacion");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(notification.getTitle())
            .setContentText(notification.getBody())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setSmallIcon(R.mipmap.ic_launch)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0, notificationBuilder.build());
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:27,代码来源:MyFirebaseMessagingService.java

示例10: onReceive

import android.media.RingtoneManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Intent intent2 = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2,
            PendingIntent.FLAG_ONE_SHOT);

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

    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setAutoCancel(true)   //Automatically delete the notification
            .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon
            .setContentIntent(pendingIntent)
            .setContentTitle("Time to hydrate")
            .setContentText("Drink a glass of water now")
            .setCategory(Notification.CATEGORY_REMINDER)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSound(defaultSoundUri);


    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(0, notificationBuilder.build());

    Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show();
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:26,代码来源:WaterReminderReceiver.java

示例11: onActivityResult

import android.media.RingtoneManager; //导入依赖的package包/类
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (resultCode == Activity.RESULT_OK && requestCode == 5) {
        Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

        SharedPreferences myPrefs = this.getSharedPreferences(SettingConstants.PREFERENCES, MODE_PRIVATE);
        SharedPreferences.Editor prefsEditor = myPrefs.edit();
        if (uri != null) {
            prefsEditor.putString(SettingConstants.SOUNDFILE, uri.toString());
            prefsEditor.apply();
            Log.d(TAG, "Chosen sound: " + uri.toString());

            Answers.getInstance().logCustom(new CustomEvent("Sound")
                    .putCustomAttribute("uri", uri.toString()));
        } else {
            prefsEditor.putString(SettingConstants.SOUNDFILE, "");
            prefsEditor.apply();
        }
        TextView soundTV = (TextView) findViewById(R.id.textViewCurrentSound);
        soundTV.setText(myPrefs.getString(SettingConstants.SOUNDFILE, SettingConstants.SOUNDFILE_DEFAULT));
    }
}
 
开发者ID:jpmeijers,项目名称:ttnmapper_android_v2,代码行数:23,代码来源:SettingsActivity.java

示例12: getNotifications

import android.media.RingtoneManager; //导入依赖的package包/类
public Map<String, String> getNotifications() {
    RingtoneManager manager = new RingtoneManager(getActivity());
    manager.setType(RingtoneManager.TYPE_NOTIFICATION);
    Cursor cursor = manager.getCursor();
    Map<String, String> list = new HashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());
        list.put(notificationTitle, notificationUri.toString());
    }

    list.put(getString(R.string.ringtone_vk), Settings.get()
            .notifications()
            .getDefNotificationRingtone());
    return list;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:17,代码来源:NotificationPreferencesFragment.java

示例13: getTone

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Get the tone from {@link RingtoneManager} for any given type. It will add title as the key and
 * uri of the sound as value in given hashmap.
 *
 * @param context       instance of the caller
 * @param type          type of the ringtone from {@link RingtonePickerDialog.Builder#TYPE_NOTIFICATION},
 *                      {@link RingtonePickerDialog.Builder#TYPE_RINGTONE} or {@link RingtonePickerDialog.Builder#TYPE_ALARM}
 * @param ringTonesList Hash map in which alarm tone will be added.
 */
private static void getTone(Context context,
                            int type,
                            @NonNull HashMap<String, Uri> ringTonesList) {
    RingtoneManager mRingtoneMgr = new RingtoneManager(context);

    mRingtoneMgr.setType(type);
    Cursor ringsCursor = mRingtoneMgr.getCursor();

    while (ringsCursor.moveToNext()) {
        ringTonesList.put(ringsCursor.getString(RingtoneManager.TITLE_COLUMN_INDEX),
                Uri.parse(ringsCursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
                        + ringsCursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
    }
    ringsCursor.close();
}
 
开发者ID:kevalpatel2106,项目名称:android-ringtone-picker,代码行数:25,代码来源:RingtoneUtils.java

示例14: sendNotification

import android.media.RingtoneManager; //导入依赖的package包/类
/**
 * Method send notification
 *
 * @param message message object
 */
private void sendNotification(Message message) {
    Intent intent = new Intent(this, ChatActivity.class);
    intent.putExtra("message", message);
    intent.putExtra("id", message.getSender());
    intent.putExtra("name", name);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Chat cDa")
            .setContentText(message.getMessage())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0, notificationBuilder.build());
}
 
开发者ID:codingdojoangola,项目名称:cda-app,代码行数:29,代码来源:FirebaseService.java

示例15: sendNotification

import android.media.RingtoneManager; //导入依赖的package包/类
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    int requestCode = 0;

    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_action_name)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    int notificationId = 0;

    notificationManager.notify(notificationId, notificationBuilder.build());
}
 
开发者ID:UTN-FRBA-Mobile,项目名称:Clases-2017c1,代码行数:27,代码来源:MyFirebaseMessagingService.java


注:本文中的android.media.RingtoneManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。