I am trying to read a file in order to send it via Wear App, but I get an OutOfMemory exception.
File file = new File(filePath);
final FileInputStream fileInputStream = new FileInputStream(file);
byte fileContent[] = new byte[(int) file.length()]; //***BOMBS HERE***
fileInputStream.read(fileContent);
fileInputStream.close();
Asset programDataAsset = Asset.createFromBytes(fileContent);
The exception states the following:
java.lang.OutOfMemoryError: Failed to allocate a 31150467 byte allocation with 2097152 free bytes and 16MB until OOM
at com.rithmio.coach.wear.TransferService.sendAssetToMobile(TransferService.java:110)
at com.rithmio.coach.wear.TransferService.onHandleIntent(TransferService.java:84)
at com.rithmio.coach.wear.TransferService$1.run(TransferService.java:60)
at java.lang.Thread.run(Thread.java:818)