Compare commits

...

5 Commits
oppo ... master

Author SHA1 Message Date
zhl
32096e8d74 修正热更无法正常运行的bug 2020-12-23 19:52:33 +08:00
zhl
b2e58d4462 更新文档 2020-11-23 17:27:59 +08:00
zhl
c0e90edc9e 增加一些注释 2020-11-19 19:21:48 +08:00
zhl
e29648f328 增加登陆和支付回调的示例代码 2020-11-19 19:09:03 +08:00
zhl
36e83cdd26 修改退出流程 2020-11-19 17:52:25 +08:00
5 changed files with 37 additions and 5 deletions

View File

@ -6,4 +6,9 @@ key/publish_key
key store pass: 7654321Kingsome_
key alias: release
key pass: 7654321Kingsome_
vivo key alias: vivo
oppo key alias: oppo
xiaomi key alias: release
```

View File

@ -128,7 +128,7 @@ public class LaunchActivity extends Activity {
*/
private void getLocalVersionInfo() {
String fileName = gameUrl.replace("index.html", "version.json");
String realPath = getFileDirByUrl(fileName);
String realPath = preloadPath + "/" + getFileDirByUrl(fileName) + "version.json" ;
File versionFile = new File(realPath);
if (versionFile.exists()) {
JSONObject data = AssetsUtil.readJsonFromFile(this, realPath);
@ -198,7 +198,7 @@ public class LaunchActivity extends Activity {
});
}
private void preloadGame() {
String dir = preloadPath + getFileDirByUrl(gameUrl);
String dir = preloadPath + "/" + getFileDirByUrl(gameUrl);
File dirFile = new File(dir);
if (!dirFile.exists()) {
dirFile.mkdirs();

View File

@ -17,6 +17,7 @@ import android.widget.ImageView;
import android.widget.Toast;
import com.hnjc.wjtx.util.AssetsUtil;
import com.hnjc.wjtx.util.IdUtil;
import com.hnjc.wjtx.util.StorageUtil;
import com.hnjc.wjtx.util.StringUtil;
@ -98,9 +99,11 @@ public class MainActivity extends Activity {
builder.setPositiveButton("取消",null);
//显示弹框
builder.show();
return true;
} else {
return super.onKeyDown(keyCode, keyEvent);
}
return super.onKeyDown(keyCode, keyEvent);
}
private void setExternalInterfaces() {
@ -161,6 +164,18 @@ public class MainActivity extends Activity {
});
nativeAndroid.setExternalInterface("getUid", message -> {
//TODO: 平台的登陆
JSONObject obj = new JSONObject();
try {
obj.put("openid", IdUtil.getUid(this));
obj.put("token", "");
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
obj.put("errorcode", 1);
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
nativeAndroid.callExternalInterface("loginCancel", "");
}
});
nativeAndroid.setExternalInterface("@onState", message -> {
Log.e(TAG, "Get @onState: " + message);
@ -184,6 +199,14 @@ public class MainActivity extends Activity {
String productCode = jsonObject.getString("productCode");
int count = jsonObject.getInt("count");
//TODO: 平台的支付
JSONObject obj = new JSONObject();
try {
obj.put("errcode", 0);
obj.put("errmsg", "");
nativeAndroid.callExternalInterface("payResult", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
} catch (JSONException e) {
e.printStackTrace();
} catch ( Exception e ) {

View File

@ -12,6 +12,7 @@ import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -187,12 +188,15 @@ public class AssetsUtil {
*/
public static String readFromFile(Context context, String path) {
try {
InputStreamReader inputReader = new InputStreamReader(context.openFileInput(path));
FileInputStream fileInputStream = new FileInputStream(new File(path));
InputStreamReader inputReader = new InputStreamReader(fileInputStream);
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
StringBuilder result= new StringBuilder();
while((line = bufReader.readLine()) != null)
result.append(line);
fileInputStream.close();
inputReader.close();
bufReader.close();
return result.toString();

View File

@ -3,7 +3,7 @@
<string name="load_game">下载游戏资源</string>
<string name="start_game">进入游戏</string>
<string name="preload_path">preload</string>
<string name="game_url">http://local/index.html?channel=7013</string>
<string name="game_url">http://local/index.html?channel=7103</string>
<string name="local_version">1.0.0</string>
<string name="load_back">load_back</string>
<string name="launch_version">获取游戏版本</string>