Skip to content

Commit

Permalink
[1.5.0] Fix app for older devices where Charset.forName is required f…
Browse files Browse the repository at this point in the history
…or utf-8
  • Loading branch information
Wirtos committed Dec 10, 2024
1 parent f816c33 commit 13a6433
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ android {
applicationId "com.wirtos.tguydroid"
targetSdkVersion 35
minSdkVersion 16
versionCode 6
versionName '1.4.1'
versionCode 7
versionName '1.5.0'
archivesBaseName = "$applicationId-$versionName"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
25 changes: 9 additions & 16 deletions app/src/main/java/com/wirtos/tguydroid/TGuy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.annotation.Nullable;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class TGuy {
Expand All @@ -32,14 +33,10 @@ public class TGuy {
TGuy(String str, int spacing) {
byte[] res;

try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
res = str.getBytes(StandardCharsets.UTF_8);
} else {
res = str.getBytes("UTF-8");
}
} catch (UnsupportedEncodingException e) {
res = new byte[]{0x41, 0x41, 0x41, 0x41};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
res = str.getBytes(StandardCharsets.UTF_8);
} else {
res = str.getBytes(Charset.forName("UTF-8"));
}
tgobj = tguy_jni_ctor(res, spacing);
if (tgobj == 0) {
Expand All @@ -59,14 +56,10 @@ public String toString() {
if (res == null) {
return "";
}
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return new String(res, StandardCharsets.UTF_8);
} else {
return new String(res, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
return "Unsupported";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return new String(res, StandardCharsets.UTF_8);
} else {
return new String(res, Charset.forName("UTF-8"));
}
}

Expand Down

0 comments on commit 13a6433

Please sign in to comment.