Commit abc5308c authored by Sergey Galin's avatar Sergey Galin

Add getUserLocaleNames() function

parent bba3a6d3
......@@ -387,6 +387,25 @@ QString getDefaultLocaleName()
}
QStringList getUserLocaleNames()
{
QJniClass du(c_full_class_name_);
if (du.jClass())
{
return du.callStaticParamString(
"getUserLocaleNames",
"Landroid/content/Context;",
QAndroidQPAPluginGap::Context().jObject())
.split(QLatin1Char('\n'), QString::SkipEmptyParts);
}
else
{
qCritical() << "Null class:" << c_full_class_name_;
return QStringList() << QLatin1String("C");
}
}
bool checkSelfPermission(const QString & permission_name)
{
if (QAndroidQPAPluginGap::apiLevel() < 23)
......
......@@ -107,6 +107,7 @@ QString getBuildSerial();
QStringList getInstalledAppsList();
QString getDefaultLocaleName();
QStringList getUserLocaleNames();
// This function tries to find out some string which uniquely identifies this device.
// If it's not available on the device it returns an empty string.
......
......@@ -39,6 +39,7 @@ package ru.dublgis.androidhelpers;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import android.os.LocaleList;
import java.io.File;
import java.util.ArrayList;
import java.util.Set;
......@@ -678,6 +679,26 @@ public class DesktopUtils
}
public static String getUserLocaleNames(final Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // API 24 / Android 7.0
try {
final LocaleList list = context.getResources().getConfiguration().getLocales();
if (list.size() > 0) {
String result = "";
for (int i = 0; i < list.size(); ++i)
result += list.get(i).toString() + "\n";
return result;
}
} catch (final Throwable e) {
Log.e(TAG, "getUserLocaleNames exception: ", e);
}
}
return getDefaultLocaleName(context);
}
private static class ActivityInfo implements Comparable<ActivityInfo> {
private @NonNull String mPackageName = "";
private @NonNull String mName = "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment