I got a problem for learning the Android plugin
I have done the privious version that the unity project can download the file.This ensure my plugin can work but a little worry about
the activity declared in AndroidManifest.xml. when I add unitySendMessage in java code. This is so weired that the logcat show the progress value 0~100 and then turn to show unity debug log with the same message as the function it delivers. Should I revise the code with multithread or add another activity?
here is a part of JAVA code:
public class DownLoad extends UnityPlayerActivity
{
//oncreate constructor bypass
private long progress = 0L;
private long total;
File file;
public boolean downLoadFile(String httpUrl)
{
//.....
//here already got the inputstream with Url httpUrl
//is : the inputstream
//buf : a byte array as buffer
//fos : the outstream
//progress, total : int
while (count <= 100.0D) {
if (is == null)
break;
int numRead = is.read(buf);
if (numRead <= 0) {
break;
}
fos.write(buf, 0, numRead);
this.progress += numRead;
Log.d("progress", String.valueOf((float)this.progress * 100.0D / (float)this.total) + "%");
call(String.valueOf((float)this.progress * 100.0D /this.total));
}
}
}
and the call function:
public void call(String message) {
UnityPlayer.UnitySendMessage("mGameObject", "CallUnityFromJAVA", message);
}
and in unity:
public void CallUnityFromJAVA(string message)
{
Debug.Log(message + "%");
}
the logcat show:
05-31 15:55:17.387: D/progress(8694): .70286863078988%
....
...
.......
05-31 15:29:07.407: I/Unity(8694): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
05-31 15:29:07.407: I/Unity(8694): 98.97209116048147%
05-31 15:29:07.407: I/Unity(8694):
05-31 15:29:07.407: I/Unity(8694): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
05-31 15:29:07.407: I/Unity(8694): 98.97270819887842%
......
...
android progress log always show before unity log
thx~