import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.UnsupportedEncodingException;
public final class HtmlDisplayActivity extends AppCompatActivity {
fontSizeSp = 14;
}
webView.getSettings().setDefaultFontSize(fontSizeSp);
- // No way to get pure UTF-8 data into WebView
- html = Base64.encodeToString(html.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT);
+ try {
+ // No way to get pure UTF-8 data into WebView
+ // Cannot use StandardCharsets due to older Android.
+ html = Base64.encodeToString(html.getBytes("UTF-8"), Base64.DEFAULT);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Missing UTF-8 support?!", e);
+ }
// Use loadURL to allow specifying a charset
webView.loadUrl("data:text/html;charset=utf-8;base64," + html);
webView.activity = this;
buf.readFully(zipBytes);
try {
final byte[] bytes = StringUtil.unzipFully(zipBytes, numBytes);
- html = new String(bytes, StandardCharsets.UTF_8);
+ // Cannot use StandardCharsets due to older Android.
+ html = new String(bytes, "UTF-8");
} catch (IOException e) {
throw new RuntimeException("Dictionary HTML data corrupted", e);
}