|
|
|
@ -16,9 +16,14 @@ import com.dev.devapi.api.SysApi;
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
@ -32,13 +37,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
int initres = intent.getIntExtra("initres", 0);
|
|
|
|
|
if (initres != 0) {
|
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
final String sn = intent.getStringExtra("sn");
|
|
|
|
|
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
notifyMpApp();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
initMpAppConfigurations(getApplicationContext(), mHandler, runnable);
|
|
|
|
|
initMpAppConfigurations(getApplicationContext(), mHandler, sn, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -48,7 +55,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean initMpAppConfigurations(final Context context, final Handler handler, final Runnable runnable) {
|
|
|
|
|
public static boolean initMpAppConfigurations(final Context context, final Handler handler, final String sn, final Runnable runnable) {
|
|
|
|
|
|
|
|
|
|
boolean existed = true;
|
|
|
|
|
String destPath = MicroPhotoContext.buildMpAppDir(context);
|
|
|
|
@ -103,6 +110,38 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(sn)) {
|
|
|
|
|
// Update SN into App.json
|
|
|
|
|
File appFile = new File(tmpDestPath, "App.json");
|
|
|
|
|
try {
|
|
|
|
|
if (appFile.exists()) {
|
|
|
|
|
|
|
|
|
|
long mtime = appFile.lastModified();
|
|
|
|
|
String content = FilesUtils.readTextFile(appFile.getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
|
|
|
|
|
jsonObject.put("CMDID", sn);
|
|
|
|
|
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
|
try {
|
|
|
|
|
fos = new FileOutputStream(appFile);
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
|
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
FilesUtils.closeFriendly(outputStreamWriter);
|
|
|
|
|
FilesUtils.closeFriendly(fos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appFile.setLastModified(mtime);
|
|
|
|
|
}
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.postDelayed(runnable, 0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|