- 添加 MainActivity 和 WebView 配置 - 添加 AssetReader JS 接口用于读取本地文件 - 支持全屏、横屏模式 - 添加错误页面和测试页面 - 添加 Gradle 构建配置和一键构建脚本
50 lines
1.3 KiB
Java
50 lines
1.3 KiB
Java
package com.iptv.app;
|
|
|
|
import android.content.Context;
|
|
import android.webkit.JavascriptInterface;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
|
|
public class AssetReader {
|
|
private Context context;
|
|
|
|
public AssetReader(Context context) {
|
|
this.context = context;
|
|
}
|
|
|
|
@JavascriptInterface
|
|
public String readFile(String path) {
|
|
try {
|
|
// path 如: "www/api/result.txt"
|
|
InputStream is = context.getAssets().open(path);
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
StringBuilder sb = new StringBuilder();
|
|
String line;
|
|
while ((line = reader.readLine()) != null) {
|
|
sb.append(line).append("\n");
|
|
}
|
|
reader.close();
|
|
return sb.toString();
|
|
} catch (IOException e) {
|
|
return "ERROR: " + e.getMessage();
|
|
}
|
|
}
|
|
|
|
@JavascriptInterface
|
|
public String readChannelData() {
|
|
return readFile("www/api/result.txt");
|
|
}
|
|
|
|
@JavascriptInterface
|
|
public boolean fileExists(String path) {
|
|
try {
|
|
context.getAssets().open(path).close();
|
|
return true;
|
|
} catch (IOException e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|