Unity makes it possible to create a game which can be exported to many platforms like – Windows, Linux, Android and IOS.
So, I have created a game in Unity (a game engine) that takes input from an Arduino based device. For serial communication, I have written a C# script that polls through all the available ports to finds the port on which the Arduino is connected to and opens it for communication.
While my solution works for Linux and Windows systems, it fails on android and throws the following error –
Error Unity IOException: Permission denied
Error Unity Rethrow as UnauthorizedAccessException: Access to the path ‘/dev’ is denied.
How do I get the permission from the android user to access this path?
I am inexperienced in android development, so just by scouring the web I was able to only tryout adding a custom android-manifest file from unity and adding a few permissions –
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<!--ADDED THESE PERMISSIONS: START-->
<uses-permission android:name="android.permission.MANAGE_USB" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
<!--ADDED THESE PERMISSIONS: END-->
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
</manifest>
Now I am currently trying to build a plugin in android-studio for doing this serial communication. But this seems like a lot of work to me just because I don’t have this permission in the Unity app. Also, getting permissions through Java/Kotlin plugin will require me to learn new things which I don’t have the bandwidth for yet.
Is there any other way to get this permission without getting into building a plugin in Java or Xamarin?