/// <summary> /// Vibrate device for specified amount of time /// </summary> /// <param name="milliseconds">Time in MS to vibrate device (500ms is default).</param> public void StartVibration(int milliseconds = 500) { using (var v = (Vibrator)Android.App.Application.Context.GetSystemService(Context.VibratorService)) { if ((int)Build.VERSION.SdkInt >= 11) { #if __ANDROID_11__ if (!v.HasVibrator) { #if DEBUG System.Diagnostics.Debug.WriteLine("Android device does not have vibrator."); #endif return; } #endif } if (milliseconds < 0) { milliseconds = 0; } try { using (var attributes = new Android.Media.AudioAttributes.Builder().SetUsage(Android.Media.AudioUsageKind.Game).Build()) v.Vibrate(milliseconds, attributes); } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine("Unable to vibrate Android device, ensure VIBRATE permission is set."); #endif } } }
/// <summary> /// Instantiates a new SimpleAudioPlayer /// </summary> public SoundPoolAudioPlayerImplementation() { soundIds = new List <int>(); sampleIds = new List <int>(); _pitchSpeed = 1; var audioAttributes = new Android.Media.AudioAttributes.Builder() .SetContentType(Android.Media.AudioContentType.Sonification) .SetUsage(Android.Media.AudioUsageKind.AssistanceSonification) .SetLegacyStreamType(Android.Media.Stream.Music) .Build(); pool = new Android.Media.SoundPool.Builder() .SetMaxStreams(MaxStreams) .SetAudioAttributes(audioAttributes) .Build(); pool.LoadComplete += Pool_LoadComplete; SetVolume(_volume, _balance); }
void CreateNotificationChannel() { var alarmAttributes = new Android.Media.AudioAttributes.Builder() .SetContentType(Android.Media.AudioContentType.Unknown) .SetUsage(Android.Media.AudioUsageKind.NotificationRingtone).Build(); if (Build.VERSION.SdkInt < BuildVersionCodes.O) { return; } var name = "BitChute"; var description = "BitChute for Android"; var nameBackgroundPlayback = "BitChute Background Streaming"; var channelSilent = new Android.App.NotificationChannel(CHANNEL_ID, name + " Silent", Android.App.NotificationImportance.High) { Description = description }; var channel = new Android.App.NotificationChannel(CHANNEL_ID + 1, name, Android.App.NotificationImportance.High) { Description = description }; var backChannel = new Android.App.NotificationChannel(BACKGROUND_CHANNEL_ID, nameBackgroundPlayback, Android.App.NotificationImportance.Max) { Description = description, Importance = NotificationImportance.Max, LockscreenVisibility = NotificationVisibility.Public }; channel.LockscreenVisibility = NotificationVisibility.Public; var notificationManager = (Android.App.NotificationManager)GetSystemService(NotificationService); channelSilent.SetSound(null, null); backChannel.SetSound(null, null); notificationManager.CreateNotificationChannel(channel); notificationManager.CreateNotificationChannel(channelSilent); notificationManager.CreateNotificationChannel(backChannel); }
public static async void SendNotifications(List <CustomNotification> notificationList) { await Task.Run(() => { try { if (_notificationManager == null) { _notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(Android.App.Application.Context); } if (notificationList.Count == 0) { return; } int notePos = 0; foreach (var note in notificationList) { var resultIntent = new Intent(Android.App.Application.Context, typeof(MainActivity)); var valuesForActivity = new Bundle(); valuesForActivity.PutInt(MainActivity.COUNT_KEY, _count); valuesForActivity.PutString("URL", note.NoteLink); resultIntent.SetAction(MainPlaybackSticky.ActionLoadUrl); resultIntent.PutExtras(valuesForActivity); var resultPendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, MainActivity.NOTIFICATION_ID, resultIntent, PendingIntentFlags.UpdateCurrent); resultIntent.AddFlags(ActivityFlags.SingleTop); var alarmAttributes = new Android.Media.AudioAttributes.Builder() .SetContentType(Android.Media.AudioContentType.Sonification) .SetUsage(Android.Media.AudioUsageKind.Notification).Build(); if (!_sentNotificationList.Contains(note) && notePos == 0) { var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.CHANNEL_ID + 1) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle(note.NoteText) .SetNumber(1) .SetSmallIcon(Resource.Drawable.bitchute_notification2) .SetContentText(note.NoteType) .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityMin); MainActivity.NOTIFICATION_ID++; // publish the notification: //var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx); _notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build()); _sentNotificationList.Add(note); notePos++; } else if (!_sentNotificationList.Contains(note)) { var builder = new Android.Support.V4.App.NotificationCompat.Builder(Android.App.Application.Context, MainActivity.CHANNEL_ID) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle(note.NoteText) // Set the title .SetNumber(1) // Display the count in the Content Info //.SetLargeIcon(_notificationBMP) // This is the icon to display .SetSmallIcon(Resource.Drawable.bitchute_notification2) .SetContentText(note.NoteType) .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityLow); MainActivity.NOTIFICATION_ID++; // publish the notification: //var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx); _notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build()); _sentNotificationList.Add(note); notePos++; } MainPlaybackSticky.NotificationsHaveBeenSent = true; } } catch { } }); }