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


Java NotificationChannel.setSound方法代码示例

本文整理汇总了Java中android.app.NotificationChannel.setSound方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationChannel.setSound方法的具体用法?Java NotificationChannel.setSound怎么用?Java NotificationChannel.setSound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.NotificationChannel的用法示例。


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

示例1: onCreate

import android.app.NotificationChannel; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
                getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.setSound(null, null);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder builder = new Notification.Builder(
                this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.apply_on_boot))
                .setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationId.APPLY_ON_BOOT, builder.build());
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:20,代码来源:ApplyOnBootService.java

示例2: createNotificationChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence name = MobiComKitConstants.PUSH_NOTIFICATION_NAME;
    ;
    int importance = NotificationManager.IMPORTANCE_HIGH;
    if (mNotificationManager.getNotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION) == null) {
        NotificationChannel mChannel = new NotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION, name, importance);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.GREEN);
        if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
            mChannel.setShowBadge(true);
        } else {
            mChannel.setShowBadge(false);
        }
        if (ApplozicClient.getInstance(context).getVibrationOnNotification()) {
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        }
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
        mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), audioAttributes);
        mNotificationManager.createNotificationChannel(mChannel);

    }

}
 
开发者ID:AppLozic,项目名称:Applozic-Android-Chat-Sample,代码行数:29,代码来源:RegisterUserClientService.java

示例3: createNotificationChannelForAndroidO

import android.app.NotificationChannel; //导入方法依赖的package包/类
private void createNotificationChannelForAndroidO() {
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mNotificationManager != null) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                "Nova Music Player", NotificationManager.IMPORTANCE_LOW);

        // Configure the notification channel.
        notificationChannel.setDescription("Channel of Nova Music Player");
        notificationChannel.enableLights(false);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.setSound(null, null);
        notificationChannel.enableVibration(false);
        notificationChannel.setShowBadge(false);
        mNotificationManager.createNotificationChannel(notificationChannel);
    }
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:17,代码来源:NovaNotificationManager.java

示例4: initNotificationManager

import android.app.NotificationChannel; //导入方法依赖的package包/类
private void initNotificationManager() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final Stopwatch watch = Stopwatch.createStarted();
        final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        final NotificationChannel received = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_RECEIVED,
                getString(R.string.notification_channel_received_name), NotificationManager.IMPORTANCE_DEFAULT);
        received.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received),
                new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build());
        nm.createNotificationChannel(received);

        final NotificationChannel ongoing = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_ONGOING,
                getString(R.string.notification_channel_ongoing_name), NotificationManager.IMPORTANCE_LOW);
        nm.createNotificationChannel(ongoing);

        final NotificationChannel important = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_IMPORTANT,
                getString(R.string.notification_channel_important_name), NotificationManager.IMPORTANCE_HIGH);
        nm.createNotificationChannel(important);

        log.info("created notification channels, took {}", watch);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:WalletApplication.java

示例5: CreateChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
public static void CreateChannel(String identifier, String name, String description, int importance, String soundName, int enableLights, int lightColor, int enableVibration, long[] vibrationPattern, String bundle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;

    channels.add(identifier);

    NotificationManager nm = (NotificationManager) UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel(identifier, name, importance);
    channel.setDescription(description);
    if (soundName != null) {
        Resources res = UnityPlayer.currentActivity.getResources();
        int id = res.getIdentifier("raw/" + soundName, null, UnityPlayer.currentActivity.getPackageName());
        AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
        channel.setSound(Uri.parse("android.resource://" + bundle + "/" + id), audioAttributes);
    }
    channel.enableLights(enableLights == 1);
    channel.setLightColor(lightColor);
    channel.enableVibration(enableVibration == 1);
    if (vibrationPattern == null)
        vibrationPattern = new long[] { 1000L, 1000L };
    channel.setVibrationPattern(vibrationPattern);
    nm.createNotificationChannel(channel);
}
 
开发者ID:Agasper,项目名称:unity-android-notifications,代码行数:24,代码来源:UnityNotificationManager.java

示例6: createAlarmChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
private void createAlarmChannel(String uri) {
    Log.e("KCA-A", "recv: " + uri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
        boolean isVibrate = soundKind.equals(getString(R.string.sound_kind_value_mixed)) || soundKind.equals(getString(R.string.sound_kind_value_vibrate));
        notificationManager.deleteNotificationChannel(ALARM_CHANNEL_ID);
        while (!alarmChannelList.isEmpty()) {
            notificationManager.deleteNotificationChannel(alarmChannelList.poll());
        }

        AudioAttributes.Builder attrs = new AudioAttributes.Builder();
        attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
        attrs.setUsage(AudioAttributes.USAGE_NOTIFICATION);

        String channel_name = createAlarmId(uri, isVibrate);
        alarmChannelList.add(channel_name);
        NotificationChannel channel = new NotificationChannel(alarmChannelList.peek(),
                getStringWithLocale(R.string.notification_appinfo_title), NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(Uri.parse(uri), attrs.build());
        channel.enableVibration(isVibrate);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        notificationManager.createNotificationChannel(channel);
    }
}
 
开发者ID:antest1,项目名称:kcanotify,代码行数:25,代码来源:KcaAlarmService.java

示例7: createNotificationChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.O)
public void createNotificationChannel() {
    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    if (notificationManager != null) {
        NotificationChannel channel = new NotificationChannel(
                Constants.NOTIFICATION_CHANNEL_ID_RS,
                getString(R.string.notification_channel_running_status),
                NotificationManager.IMPORTANCE_DEFAULT
        );
        channel.setShowBadge(false);
        channel.enableLights(false);
        channel.enableVibration(false);
        channel.setSound(null, null);

        notificationManager.createNotificationChannel(channel);
    }
}
 
开发者ID:fython,项目名称:Blackbulb,代码行数:18,代码来源:BlackbulbApplication.java

示例8: addNotificationAttributes

import android.app.NotificationChannel; //导入方法依赖的package包/类
@RequiresApi(api = 26)
private static NotificationChannel addNotificationAttributes(final NotificationChannel notificationChannel) {
    final int notificationColor = ContextCompat.getColor(BaseApplication.get(), R.color.colorPrimary);
    final Uri notificationSound = Uri.parse("android.resource://" + BaseApplication.get().getPackageName() + "/" + R.raw.notification);

    notificationChannel.enableLights(true);
    notificationChannel.setLightColor(notificationColor);
    notificationChannel.enableVibration(true);
    notificationChannel.setSound(notificationSound,
            new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setFlags(AudioAttributes.USAGE_NOTIFICATION)
                    .build()
    );

    return notificationChannel;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:18,代码来源:ToshiNotificationBuilder.java

示例9: createNotificationChannels

import android.app.NotificationChannel; //导入方法依赖的package包/类
/**
 * Create notification channels required for displayal of notifications on >=API O
 */
@RequiresApi(api = Build.VERSION_CODES.O)
public static void createNotificationChannels(Context context) {
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    String channelId = ApplicationConstants.MEDIA_NOTIFICATION_CHANNEL_ID;
    CharSequence userVisibleChannelName = context.getString(R.string.media_notification_channel_name);
    String userVisibleDescription = context.getString(R.string.media_notification_channel_description);

    int notificationImportance = NotificationManager.IMPORTANCE_DEFAULT;
    AudioAttributes audioAttributes =
        new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build();

    NotificationChannel mediaNotificationChannel = new NotificationChannel(channelId, userVisibleChannelName, notificationImportance);
    mediaNotificationChannel.setDescription(userVisibleDescription);
    mediaNotificationChannel.enableVibration(false);
    mediaNotificationChannel.enableLights(false);
    mediaNotificationChannel.setSound(Uri.EMPTY, audioAttributes);

    mNotificationManager.createNotificationChannel(mediaNotificationChannel);
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:25,代码来源:NotificationUtil.java

示例10: createNotificationChannels

import android.app.NotificationChannel; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannels() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationChannel foreground = new NotificationChannel("foreground", getString(R.string.channel_foreground), NotificationManager.IMPORTANCE_MIN);
    foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(foreground);

    NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT);
    notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(notify);

    NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT);
    access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
    nm.createNotificationChannel(access);
}
 
开发者ID:M66B,项目名称:NetGuard,代码行数:17,代码来源:ApplicationEx.java

示例11: NotificationHandler

import android.app.NotificationChannel; //导入方法依赖的package包/类
public NotificationHandler(Context context) {
    ((SyncthingApp) context.getApplicationContext()).component().inject(this);
    mContext = context;
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mPersistentChannel = new NotificationChannel(
                CHANNEL_PERSISTENT, mContext.getString(R.string.notifications_persistent_channel),
                NotificationManager.IMPORTANCE_MIN);
        mPersistentChannel.enableLights(false);
        mPersistentChannel.enableVibration(false);
        mPersistentChannel.setSound(null, null);
        mNotificationManager.createNotificationChannel(mPersistentChannel);
        mInfoChannel = new NotificationChannel(
                CHANNEL_INFO, mContext.getString(R.string.notifications_other_channel),
                NotificationManager.IMPORTANCE_LOW);
        mPersistentChannel.enableVibration(false);
        mPersistentChannel.setSound(null, null);
        mNotificationManager.createNotificationChannel(mInfoChannel);
    } else {
        mPersistentChannel = null;
        mInfoChannel = null;
    }
}
 
开发者ID:syncthing,项目名称:syncthing-android,代码行数:25,代码来源:NotificationHandler.java

示例12: getChatMessageChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
public static NotificationChannel getChatMessageChannel(Context context){
    String channelName = context.getString(R.string.message_channel);

    NotificationChannel channel = new NotificationChannel(CHAT_MESSAGE_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);
    channel.setSound(NotificationHelper.findNotificationSound(), ATTRIBUTES);
    channel.enableLights(true);
    channel.enableVibration(true);
    return channel;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:11,代码来源:AppNotificationChannels.java

示例13: getGroupChatMessageChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
public static NotificationChannel getGroupChatMessageChannel(Context context){
    String channelName = context.getString(R.string.group_message_channel);
    NotificationChannel channel = new NotificationChannel(GROUP_CHAT_MESSAGE_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT);
    channel.setSound(NotificationHelper.findNotificationSound(), ATTRIBUTES);
    channel.enableLights(true);
    channel.enableVibration(true);
    return channel;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:10,代码来源:AppNotificationChannels.java

示例14: makeNotifyChans

import android.app.NotificationChannel; //导入方法依赖的package包/类
private void makeNotifyChans(NotificationManager notifyManager)
{
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;

    ArrayList<NotificationChannel> chans = new ArrayList<>();
    NotificationChannel defaultChan = new NotificationChannel(DEFAULT_CHAN_ID, getString(R.string.def),
                                                       NotificationManager.IMPORTANCE_DEFAULT);
    Uri sound = Uri.parse(pref.getString(getString(R.string.pref_key_notify_sound),
                                         SettingsManager.Default.notifySound));
    defaultChan.setSound(sound, getNotifyAudioAttributes());

    if (pref.getBoolean(getString(R.string.pref_key_vibration_notify),
                        SettingsManager.Default.vibrationNotify)) {
        defaultChan.enableVibration(true);
        /* TODO: Make the ability to customize vibration */
        defaultChan.setVibrationPattern(new long[]{1000}); /* ms */
    } else {
        defaultChan.enableVibration(false);
    }

    if (pref.getBoolean(getString(R.string.pref_key_led_indicator_notify),
                        SettingsManager.Default.ledIndicatorNotify)) {
        int color = pref.getInt(getString(R.string.pref_key_led_indicator_color_notify),
                                SettingsManager.Default.ledIndicatorColorNotify(getApplicationContext()));
        defaultChan.enableLights(true);
        defaultChan.setLightColor(color);
    } else {
        defaultChan.enableLights(false);
    }
    chans.add(defaultChan);
    chans.add(new NotificationChannel(FOREGROUND_NOTIFY_CHAN_ID, getString(R.string.foreground_notification),
                                      NotificationManager.IMPORTANCE_LOW));
    notifyManager.createNotificationChannels(chans);
}
 
开发者ID:proninyaroslav,项目名称:libretorrent,代码行数:36,代码来源:TorrentTaskService.java

示例15: createNotificationChannels

import android.app.NotificationChannel; //导入方法依赖的package包/类
private void createNotificationChannels() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        NotificationChannel mChannel = prepareNotificationChannel(
                NOTIFICATIONCHANNEL_TRACKER_STATUS,
                getString(R.string.channel_name_status),
                getString(R.string.channel_description_status),
                NotificationManager.IMPORTANCE_LOW);
        mNotificationManager.createNotificationChannel(mChannel);

        mChannel = prepareNotificationChannel(
                NOTIFICATIONCHANNEL_SERVICE_STATUS,
                getString(R.string.channel_name_service),
                getString(R.string.channel_description_service),
                NotificationManager.IMPORTANCE_MIN);
        mChannel.setShowBadge(false);
        mNotificationManager.createNotificationChannel(mChannel);

        mChannel = prepareNotificationChannel(
                NOTIFICATIONCHANNEL_NEW_ACCESS_POINT,
                getString(R.string.channel_name_new_access_points),
                getString(R.string.channel_description_new_access_points),
                NotificationManager.IMPORTANCE_LOW);
        mChannel.enableLights(true);
        mChannel.setLightColor(R.color.highlight);
        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mChannel.setSound(uri, new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build());
        mNotificationManager.createNotificationChannel(mChannel);
    }
}
 
开发者ID:firebirdberlin,项目名称:tinytimetracker,代码行数:37,代码来源:TinyTimeTracker.java


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