Set Vibrate

Set Vibrate
set_vibrate

Category: Native
Pulses the vibration hardware on the device for time in milliseconds, if such hardware exists.

Input parameters:

  • Milliseconds — time in milliseconds (data type Int, default value 100).

Demo: web (launch from a mobile device), android.
Scripts: SetVibrateNode.zip

For android:

  1. Do not forget to register permission for the application to use vibration (AndroidManifest.xml):
    <uses-permission android: name = "android.permission.VIBRATE" />

  2. If the target version is Android SDK < 26, then the project will not be built in Android Studio, because the android.os.VibrationEffect module is bound there, which appeared only from this version. We’ll have to edit the Kha project template for android.

4 Likes

I am planning to try to adjust the resolution for AndroidManifest.xml for vibration.
Tasks:

  1. For settings, add a tab to the Armory Project named Android. It will include settings for orientation, permissions and others.
  2. Add a setting permissions (as done with orientation).
  3. When adding a logical node to the project, automatically set this setting.
  4. Correct the code for generating the manifest (blender/arm/write_data.py).
2 Likes

The current version looks like this:
android_settings

Questions:

  1. What permissions to add?
    So far so far:

     items = [('VIBRATE', 'Vibrate', 'Allows access to the vibrator'),
              ('INTERNET', 'Internet', 'Allows applications to open network sockets'),
              ('ACCESS_COARSE_LOCATION', 'Access Coarse Location', 'Allows an app to access approximate location'),
              ('ACCESS_NETWORK_STATE', 'Access Network State', 'Allows applications to access information about networks'),
              ('ACCESS_FINE_LOCATION', 'Access Fine Location', 'Allows an app to access precise location'),
              ('READ_EXTERNAL_STORAGE', 'Read External Storage', 'Allows an application to read from external storage.'),
              ('WRITE_EXTERNAL_STORAGE', 'Write External Storage', 'Allows an application to write to external storage'),
              ('ACCESS_WIFI_STATE', 'Access Wi-Fi State', 'Allows applications to access information about Wi-Fi networks')],
    
  2. SDK version and ABIs are specified in the build.gradle file. Based on the current documentation you cannot influence it through the API, you need to complete it in Kinc (Exporters/AndroidExporter.ts), as was done here.
    I understand correctly?

2 Likes

@E1e5en Not sure about this, but do android orientation/ accelerometer sensors need any permissions? Also, access to camera and mic is one thing, possibly for future use?

  • No need for screen orientation.
  • You need an accelerometer to get data.
  • I don’t know exactly about the camera.

I can add whatever is currently in the documentation (https://developer.android.com/reference/android/Manifest.permission). Is everyone just needed?

Update:
There is also such a division: http://skptr.me/list_of_permissions.html

Update 2:
As for hardware, the settings for the campaign should be: https://developer.android.com/guide/topics/manifest/uses-feature-element.html#hw-features

2 Likes
  1. Expanding the build customization capabilities through khafile.js - Done PR.

  2. Added the list of permissions:

    items = [('ACCESS_COARSE_LOCATION ', 'Access Coarse Location', 'Allows an app to access approximate location'),
                      ('ACCESS_NETWORK_STATE', 'Access Network State', 'Allows applications to access information about networks'),
                      ('ACCESS_FINE_LOCATION', 'Access Fine Location', 'Allows an app to access precise location'),
                      ('ACCESS_WIFI_STATE', 'Access Wi-Fi State', 'Allows applications to access information about Wi-Fi networks'),
                      ('BLUETOOTH', 'Bluetooth', 'Allows applications to connect to paired bluetooth devices'),
                      ('BLUETOOTH_ADMIN', 'Bluetooth Admin', 'Allows applications to discover and pair bluetooth devices'),
                      ('CAMERA', 'Camera', 'Required to be able to access the camera device'),
                      ('EXPAND_STATUS_BAR', 'Expand Status Bar', 'Allows an application to expand or collapse the status bar'),
                      ('FOREGROUND_SERVICE', 'Foreground Service', 'Allows a regular application to use Service.startForeground'),
                      ('GET_ACCOUNTS', 'Get Accounts', 'Allows access to the list of accounts in the Accounts Service'),
                      ('INTERNET', 'Internet', 'Allows applications to open network sockets'),
                      ('READ_EXTERNAL_STORAGE', 'Read External Storage', 'Allows an application to read from external storage.'),
                      ('VIBRATE', 'Vibrate', 'Allows access to the vibrator'),
                      ('WRITE_EXTERNAL_STORAGE', 'Write External Storage', 'Allows an application to write to external storage')],
    
  3. Corrected the interface and added settings. The tab is inactive if the target platform android-hl is not selected.

    android_settings_v2

Settings:

  • Bundle;
  • Orientation;
  • Compile Version SDK - from 26 to 30, default 29;
  • Min Version SDK - from 14 to 30, default 14;
  • Target Version SDK - from 26 to 30, default 29;
  • Permissions - a list of permissions, if I will duplicate entries in the list, then only unique entries will be included during export. By default, the list is empty;
  • Android ABI Filters - a list of platforms to build for (arm64-v8a, armeabi-v7a, x86, x86_64). By default, the list is empty. If the list is empty, then all platforms will be used (as before). More than this (as written here) you don’t need to do it by hand. HOORAY!
  1. When adding the logical node Set Vibrate, the permission is automatically added to the list, even if the target platform android-hl has not been selected.

Questions:
The Bundle field is also used for iOS builds. Move it out of the Android Settings tab, or make it separate for Android, separate for iOS?

Scripts: AndroidSettings.zip

  1. Pull Request to extend khafile.js has been accepted, so submodules need to be updated.

  2. Returned the Bundle field to the previous place, since this value is used in several places, then let it be common.
    filed_bundle

  3. Android Settings panel:

  • invisible until the target platform android-hl is added to the list;
  • inactive until the target platform android-hl is selected in the list.
    android_settings_v3

Options:

  • Orientation;
  • Compile Version SDK - from 26 to 30, default 29;
  • Minimal Version SDK - from 14 to 30, default 14;
  • Target Version SDK - from 26 to 30, default 29;
  • Permissions - a list of permissions. If I will duplicate entries in the list, then only unique entries will be included during export. By default, the list is empty;
  • Android ABI Filters - a list of platforms to build for (arm64-v8a, armeabi-v7a, x86, x86_64). If I will duplicate entries in the list, then only unique entries will be included during export. By default, the list is empty. If the list is empty, then all platforms will be used (as before).
  1. The enum (names of permissions) and the function have been added to the utils.py modules, which adds the specified value to the list of permissions. Feature added for ease of use from different locations (different logical nodes):

     # Enum Permissions Name
     class PermissionName(Enum):
         ACCESS_COARSE_LOCATION = 'ACCESS_COARSE_LOCATION'
         ACCESS_NETWORK_STATE = 'ACCESS_NETWORK_STATE'
         ACCESS_FINE_LOCATION = 'ACCESS_FINE_LOCATION'
         ACCESS_WIFI_STATE = 'ACCESS_WIFI_STATE'
         BLUETOOTH = 'BLUETOOTH'
         BLUETOOTH_ADMIN = 'BLUETOOTH_ADMIN'
         CAMERA = 'CAMERA'
         EXPAND_STATUS_BAR = 'EXPAND_STATUS_BAR'
         FOREGROUND_SERVICE = 'FOREGROUND_SERVICE'
         GET_ACCOUNTS = 'GET_ACCOUNTS'
         INTERNET = 'INTERNET'
         READ_EXTERNAL_STORAGE = 'READ_EXTERNAL_STORAGE'
         VIBRATE = 'VIBRATE'
         WRITE_EXTERNAL_STORAGE = 'WRITE_EXTERNAL_STORAGE'
    
     # Add permission for target android
     def add_permission_target_android(permission_name_enum):
         wrd = bpy.data.worlds['Arm']
         check = False
         for item in wrd.arm_exporter_android_permission_list:
             if (item.arm_android_permissions.upper() == str(permission_name_enum.value).upper()):
                 check = True
                 break
         if not check:
             wrd.arm_exporter_android_permission_list.add()             
             wrd.arm_exporter_android_permission_list[len(wrd.arm_exporter_android_permission_list) - 1].arm_android_permissions = str(permission_name_enum.value).upper()
    
  2. When adding the logical node Set Vibrate, the permission is automatically added to the list, even if the target android-hl has not been added to the export list (using a function from utils.py).

    # Add permission for target android
    arm.utils.add_permission_target_android(arm.utils.PermissionName.VIBRATE)
    
  3. The list of permissions is specified in the post earlier.

Scripts: AndroidSettings+LN.zip

If there are no suggestions and comments, then I will do PR.

2 Likes