first commit
This commit is contained in:
parent
0c926f0da6
commit
b265831c55
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -21,7 +21,7 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
manifestPlaceholders = [
|
||||
APPID : "320924230000-2-1-32092423SJNB12202505211658160001",
|
||||
APPID : "320924230000-2-1-32092423SJNB12202507111046530001",
|
||||
// APPID : "320500220500-2-1-32050022SJ97122021091XXXXXXXXXX",
|
||||
REGIONALISMCODE : "\\0320924230000",
|
||||
// REGIONALISMCODE : "\\03205002xxxxxx",
|
||||
|
@ -34,7 +34,7 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
manifestPlaceholders = [
|
||||
APPID : "320924230000-2-1-32092423SJNB12202505211658160001",
|
||||
APPID : "320924230000-2-1-32092423SJNB12202507111046530001",
|
||||
REGIONALISMCODE : "\\0320924230000",
|
||||
NETWORKAREACODE : "\\02",
|
||||
]
|
||||
|
|
|
@ -13,26 +13,42 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.jwzs"
|
||||
tools:replace="android:allowBackup" >
|
||||
tools:replace="android:allowBackup">
|
||||
|
||||
|
||||
<meta-data android:name="appId" android:value="${APPID}"/><!-- 应用ID,当应用在平台注册后,由平台生成的平台内唯一标识 -->
|
||||
<meta-data android:name="regionalismCode" android:value="${REGIONALISMCODE}" /><!--应用归属机构代码,如:320000260300;对于纯数字字符串,请在前面增加“\0”,否则将会取出null值字符串 -->
|
||||
<meta-data android:name="networkAreaCode" android:value="${NETWORKAREACODE}" /><!--应用所属网络区域,也即应用类型(1-2-3),如:2;对于纯数字字符串,请在前面增加“\0”,否则将会取出null值字符串 -->
|
||||
<meta-data
|
||||
android:name="appId"
|
||||
android:value="${APPID}" /><!-- 应用ID,当应用在平台注册后,由平台生成的平台内唯一标识 -->
|
||||
<meta-data
|
||||
android:name="regionalismCode"
|
||||
android:value="${REGIONALISMCODE}" /><!--应用归属机构代码,如:320000260300;对于纯数字字符串,请在前面增加“\0”,否则将会取出null值字符串 -->
|
||||
<meta-data
|
||||
android:name="networkAreaCode"
|
||||
android:value="${NETWORKAREACODE}" /><!--应用所属网络区域,也即应用类型(1-2-3),如:2;对于纯数字字符串,请在前面增加“\0”,否则将会取出null值字符串 -->
|
||||
|
||||
<!-- 添加硬件加速和屏幕方向配置 -->
|
||||
<activity
|
||||
android:name=".FirstActivity"
|
||||
android:exported="true">
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:exported="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 非必要可移除 MainActivity -->
|
||||
<activity
|
||||
android:exported="false"
|
||||
android:name=".MainActivity"/>
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
<!-- 添加必要权限 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
|
||||
|
||||
</manifest>
|
|
@ -30,12 +30,12 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||
public static String ACTION_LOGIN = "com.ydjw.ua.ACTION_LOGIN";
|
||||
public static String ACTION_LOGOUT = "com.ydjw.ua.ACTION_LOGOUT";
|
||||
|
||||
protected static String appId = "320924230000-2-1-32092423SJNB12202505211658160001";
|
||||
protected static String appId = "320924230000-2-1-32092423SJNB12202507111046530001";
|
||||
// protected static String appId = "320500220500-2-1-32050022SJ97122021091XXXXXXXXXX";
|
||||
protected static String departId = "320924230000";
|
||||
// protected static String departId = "3205002xxxxxx";
|
||||
|
||||
private final String my_service_id = "320924230000-3-0400-EB013F207C9842D890327B6421C66EB2";
|
||||
private final String my_service_id = "320924230000-3-0800-5CDEC9969D674E1CBB7E2F86A697B0D7";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.pxkj.jwzs;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
|
@ -20,95 +21,49 @@ import androidx.annotation.Nullable;
|
|||
import java.io.IOException;
|
||||
|
||||
public class FirstActivity extends BaseActivity {
|
||||
|
||||
private TextView tvApiResult;
|
||||
|
||||
private WebView webView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main); // 必须先加载布局,再初始化控件
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// 初始化TextView(关键!绑定布局中的tv_api_result)
|
||||
// tvApiResult = findViewById(R.id.tv_api_result);
|
||||
|
||||
// Button btnTestApi = findViewById(R.id.btn_test_api);
|
||||
// btnTestApi.setOnClickListener(v -> {
|
||||
// tvApiResult.setText("测试中..."); // 此时tvApiResult已初始化,不会空指针
|
||||
// fetchData();
|
||||
// });
|
||||
|
||||
|
||||
// WebView webView = findViewById(R.id.webview);
|
||||
// webView.getSettings().setJavaScriptEnabled(true); // 启用JS
|
||||
// webView.setWebViewClient(new WebViewClient()); // 防止跳转浏览器
|
||||
//// webView.loadUrl("http://218.92.207.242:50022/"); // 加载H5地址
|
||||
// webView.loadUrl("http://50.146.63.127:82/app/"); // 加载H5地址
|
||||
// webView.getSettings().setDomStorageEnabled(true);
|
||||
// webView.clearCache(true); // 清除缓存
|
||||
// webView.getSettings().setUseWideViewPort(true);
|
||||
// webView.getSettings().setLoadWithOverviewMode(true);
|
||||
|
||||
|
||||
init(); // 调用父类方法
|
||||
initWebView();
|
||||
init(); // 触发认证流程
|
||||
}
|
||||
|
||||
|
||||
private void fetchData() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://50.146.63.127:82/app/api/")
|
||||
// .baseUrl("http://218.92.207.242:50021/gwgl/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
ApiService service = retrofit.create(ApiService.class);
|
||||
Call<ResponseBody> call = service.getData(); // 假设ApiService中定义的接口是正确的
|
||||
private void initWebView() {
|
||||
webView = findViewById(R.id.webview);
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
|
||||
call.enqueue(new Callback<ResponseBody>() {
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
||||
// 确保tvApiResult不为null(双重保险)
|
||||
if (tvApiResult == null) return;
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
String result = response.body().string();
|
||||
tvApiResult.setText("请求成功:\n" + result);
|
||||
} catch (IOException e) {
|
||||
tvApiResult.setText("响应解析失败:\n" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
tvApiResult.setText("HTTP错误:\n状态码=" + response.code());
|
||||
}
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
// 页面加载完成处理
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
||||
// 确保tvApiResult不为null(双重保险)
|
||||
if (tvApiResult == null) return;
|
||||
|
||||
// 显示具体错误原因(如网络不可达、超时等)
|
||||
String errorMsg = "请求失败:\n";
|
||||
if (t.getMessage() != null) {
|
||||
errorMsg += t.getMessage();
|
||||
} else {
|
||||
errorMsg += "未知错误";
|
||||
}
|
||||
tvApiResult.setText(errorMsg);
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected void refresh() {
|
||||
runOnUiThread(() -> {
|
||||
String url = SpUtils.getString(this, "TARGET_URL", "");
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
webView.loadUrl(url);
|
||||
}
|
||||
// 移除跳转到MainActivity的代码
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
|
||||
String targetUrl = SpUtils.getString(this, "TARGET_URL", "");
|
||||
if (!TextUtils.isEmpty(targetUrl)) {
|
||||
WebView webView = findViewById(R.id.webview);
|
||||
webView.loadUrl(targetUrl); // 加载绑定服务ID的网址
|
||||
} else {
|
||||
Toast.makeText(this, "未获取到有效网址", Toast.LENGTH_SHORT).show();
|
||||
protected void onDestroy() {
|
||||
if (webView != null) {
|
||||
webView.destroy();
|
||||
webView = null;
|
||||
}
|
||||
// 寻址成功后,在这跳转下个页面
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,8 @@ public class MainActivity extends BaseActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
// 所有其它页面均继承BaseActivity
|
||||
|
||||
// 不自动跳转,仅作为备用入口
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue