添加apk层面供js调用的显示隐私政策和用户协议的方法

This commit is contained in:
zhl 2021-10-28 10:32:47 +08:00
parent 9e534c5184
commit e611a5b4f4

View File

@ -1,6 +1,7 @@
package com.hnjc.wjtx;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
@ -13,6 +14,8 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
@ -40,6 +43,7 @@ public class MainActivity extends Activity {
private ImageView launchScreenImageView = null;
private FrameLayout rootLayout = null;
private Vibrator vibrator;
private boolean alterShowed;
@Override
@ -178,6 +182,14 @@ public class MainActivity extends Activity {
Log.d(TAG, "showToast: " + message);
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
});
nativeAndroid.setExternalInterface("showPrivacy", message -> {
Log.d(TAG, "showPrivacy: " + message);
runOnUiThread(this::showPrivacy);
});
nativeAndroid.setExternalInterface("showAgreement", message -> {
Log.d(TAG, "showAgreement: " + message);
runOnUiThread(this::showAgreement);
});
nativeAndroid.setExternalInterface("getUid", message -> {
GameCenterSDK.getInstance().doLogin(this, new ApiCallback() {
@Override
@ -348,5 +360,41 @@ public class MainActivity extends Activity {
drawable.setCallback(null);
launchScreenImageView = null;
}
private void showPrivacy() {
String url = "https://privacy3.kingsome.cn/";
alertWebview(url);
}
private void showAgreement() {
String url = "https://privacy2.kingsome.cn/user_agreement.html";
alertWebview(url);
}
private void alertWebview(String url) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
WebView mwebView = new WebView(this);
this.alterShowed = false;
mwebView.loadUrl(url);
mwebView.setWebViewClient( new WebViewClient() {
//设置结束加载函数
@Override
public void onPageFinished(WebView view, String url) {
if (!alterShowed) {
alterShowed = true;
builder.show();
}
}
}
);
builder.setPositiveButton( "取消", null );
builder.setView( mwebView );
builder.setPositiveButton("确定", (dialog, which) -> {
dialog.dismiss();
});
// builder.setNegativeButton("拒绝", (dialog, which) -> {
// //用户不同意隐私协议不通过Demo在此处退出游戏接入方可按自己要求处理但不能调用MiCommplatform.getInstance().onUserAgreed(this);
// dialog.dismiss();
// android.os.Process.killProcess(android.os.Process.myPid());
// });
}
}