I am having problem with serial ports on my android phone. In Unity editor everything works fine.
First I am getting list of all serial ports, then i connect to the one i need and i get data from it.
Now when i export my app to android phone, i get following error:
I thought it might be problem with bluetooth permission, i added it in my android manifest but it doesnt get rid of the error.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jj.ll" xmlns:tools="http://schemas.android.com/tools" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
And this is my c# code for getting serial port names.
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;
public class DataGathering : MonoBehaviour {
string[] ports;
void Start () {
lastDigits = new List <string>();
checkArray = new List <string>();
ports = new string[10];
filePath = Application.persistentDataPath;
ports = SerialPort.GetPortNames();
for(var k = 0; k < ports.Length; k++)
{
Debug.Log(ports[k]);
}
/*if(GameObject.Find("Info")!=null)
{
subjectID = int.Parse(GameObject.Find("Info").transform.GetChild(1).name);
testID = int.Parse(GameObject.Find("Info").transform.GetChild(0).name);
}
if(File.Exists(filePath+""+subjectID+"_"+testID+".txt"))
{
File.Delete(filePath+""+subjectID+"_"+testID+".txt");
}
writer = new StreamWriter(filePath+""+subjectID+"_"+testID+".txt", true);*/
}