Sunday, September 4, 2016

Cordova add local notifications with default sound



1. add plugin Local-Notification
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications

2. To test a sample, In onDeviceReady, add below. This will show the notification after about a minute after you launch your app. You can close the app or minimize it (ie; go launch another app or go to home page)


        var date = new Date();
        date = new Date(date.getTime() + 1 * 60000) // add a minute from now

        cordova.plugins.notification.local.schedule({
            id: 1,
            title: "My Notification Title",
            message: "My Notification Body",
            at: date,
            sound: "res://platform_default"
        });

Android emulator add ringtone and notification sounds

The default android emulator do not come with any sounds, like ringtones or notification sounds. You can check this by going to the settings --> Sound option and see whats set for ringtone or notifications. By default, this will be set as None.

To add sounds locate mp3 file(s) you want to use and put it into a folder, for example create a  folder sounds and copy the file(s) there. you can download some from www.freesound.org if needed

Run the AVD (Android Virtual Device) manager and click edit on the AVD name you want to use. Make sure SD card option is selected and a size is provided.  About 100MB will be more than enough. Click OK to and close.

Now fire up the emulator ( by clicking start in AVD manager) and once its running, come to the command prompt. Assuming you have android tools in your path (ex: "C:\Program Files (x86)\Android\android-sdk\platform-tools\") , issue below command
adb devices

If all is well, it should show the emulator device details we are connecting to.
for example

C:\>"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" devices
List of devices attached
emulator-5554   device

Make a note of the below folders

SD-Card
/mnt/sdcard/alarms
/mnt/sdcard/notifications
/mnt/sdcard/ringtones

Form commands like below to copy the mp3 files to your emulator where sounds is the folder where you have stored your local copy of mp3 files to be copied

C:\Users\myname\Downloads>adb push sounds /mnt/sdcard/ringtones
push: sounds/ding.mp3 -> /mnt/sdcard/ringtones/ding.mp3
1 file pushed. 0 files skipped.
584 KB/s (24912 bytes in 0.041s)

C:\Users\myname\Downloads>adb push sounds /mnt/sdcard/notifications
push: sounds/ding.mp3 -> /mnt/sdcard/notifications/ding.mp3
1 file pushed. 0 files skipped.
619 KB/s (24912 bytes in 0.039s)

Now restart your emulator, and the sounds should show up in setting. You can select the appropriate sounds now!

You may even skip the SD card and directly copy to the system folders (I haven't tested this)
Android OS System
/system/media/audio/alarms
/system/media/audio/notifications
/system/media/audio/ringtones

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...