Cymro
Cymro

Reputation: 41

How to retrieve the default notification vibration pattern in android?

As you can see in the NotificationChannel data below the mVibrationEnabled flag is set to true however there is no pattern included so the OS just plays the default notification pattern.

////////////////////////////////////////////////////////////////////////////////////// [NotificationChannel{mId='your_channel_id', mName=Your Channel Name, mDescription=hasDescription , mImportance=4, mBypassDnd=false, mLockscreenVisibility=-1000, mSound=content://settings/system/notification_sound, mLights=false, mLightColor=0, mVibration=null, mUserLockedFields=0, mUserVisibleTaskShown=false, mVibrationEnabled=true, mShowBadge=true, mDeleted=false, mDeletedTimeMs=-1, mGroup='null', mAudioAttributes=AudioAttributes: usage=USAGE_NOTIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x800 tags= bundle=null, mBlockableSystem=false, mAllowBubbles=-1, mImportanceLockedByOEM=false, mImportanceLockedDefaultApp=false, mOriginalImp=4, mParent=null, mConversationId=null, mDemoted=false, mImportantConvo=false, mSoundMissingReason=0}] //////////////////////////////////////////////////////////////////////////////////////

I am writing an app that intercepted the notification and removes the notification instantly so the OS does not play the vibration pattern, and I want to play the default vibration pattern at a later time. Most Channel data includes a custom pattern so in those cases I can get the long[] associated with the notification.

I have looked hard and cannot find a way to ask the OS for the long[] pattern of the default notification. I can get the default sound but not the pattern.

Any help would be very much appreciated.

I have looked everywhere I can think of for this information but to no avail.

Upvotes: 0

Views: 60

Answers (1)

Cymro
Cymro

Reputation: 41

Thanks to Mike M who is a star I am posting the java solution to the question I asked.

long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250}; 

public long[] getDefaultNotificationVibratePattern()
  {
  int[] systemitems = Resources.getSystem().getIntArray(
  Resources.getSystem().getIdentifier(
    "config_defaultNotificationVibePattern", 
    "array", 
    "android"));
  long[] long_vibrate = new long[systemitems.length];
  for(int i = 0; i < systemitems.length; i++) 
    {
    long_vibrate[i] = (long) systemitems[i];
    }
  
  if(systemitems.length == 0) 
     {
     return DEFAULT_VIBRATE_PATTERN;
    }
 return long_vibrate;
 }

Upvotes: 1

Related Questions