/**
   * Beeps the device for a given number of times. By default, it will beep once. If the user
   * explicitly sets the beep count to zero, it will play the applications notification profile. The
   * application profile playback sequence is controlled by the user.
   *
   * @param args JSONArray formatted as [ count ] count: specifies the number of times to beep the
   *     device (default: 1).
   * @return A CommandResult object with the success or failure state for beeping the device.
   */
  public static PluginResult execute(JSONArray args) {
    PluginResult result = null;

    if (Alert.isAudioSupported()) {

      try {
        int repeatCount = 1;
        if (args.length() > 0 && !args.isNull(0)) {
          repeatCount = args.getInt(0);
        }

        // play tone n times
        if (repeatCount > 0) {
          playTone(repeatCount);
        }
        // FIXME: unsupported on other platforms
        // send notification event to application profile
        else {
          NotificationsManager.triggerImmediateEvent(PhoneGapExtension.getAppID(), 0, null, null);
        }
      } catch (JSONException e) {
        Logger.log(BeepAction.class.getName() + ": " + e);
        result = new PluginResult(PluginResult.Status.JSONEXCEPTION, e.getMessage());
      } catch (Exception e) {
        Logger.log(BeepAction.class.getName() + ": " + e);
        result = new PluginResult(PluginResult.Status.IOEXCEPTION, e.getMessage());
      }

      result = new PluginResult(PluginResult.Status.OK);
    } else {
      result = new PluginResult(PluginResult.Status.ILLEGALACCESSEXCEPTION, "Audio not supported");
    }

    return result;
  }
Exemple #2
0
 /**
  * Checks if vibration can be controlled by the application
  *
  * @return true when the vibration can be controlled by the application
  */
 public static boolean isVibrateSupported() {
   synchronized (vibrateLock) {
     boolean isSupported = false;
     // #if polish.android
     isSupported = true;
     // #elif polish.blackberry
     isSupported = net.rim.device.api.system.Alert.isVibrateSupported();
     // #elif polish.api.nokia-ui && !polish.api.midp2
     try {
       com.nokia.mid.ui.DeviceControl.startVibra(0, 1);
       isSupported = true;
     } catch (IllegalStateException e) {
       // no vibration support
     }
     // #elif polish.api.samsung
     isSupported = com.samsung.util.Vibration.isSupported();
     // #elif polish.midp2 && polish.usePolishGui
     isSupported = StyleSheet.display.vibrate(0);
     // #endif
     return isSupported;
   }
 }