Skip to content

Commit 125494e

Browse files
committed
STEVE - adding support for Device/Platform info
1 parent 20f7027 commit 125494e

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

cocos/platform/android/CCApplication-android.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ THE SOFTWARE.
3030
#include "platform/android/jni/JniHelper.h"
3131
#include "platform/CCApplication.h"
3232
#include "base/CCDirector.h"
33-
#include <android/log.h>
3433
#include <jni.h>
3534
#include <cstring>
3635

cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ of this software and associated documentation files (the "Software"), to deal
4343
import android.os.ParcelFileDescriptor;
4444
import android.os.Vibrator;
4545
import android.preference.PreferenceManager.OnActivityResultListener;
46+
import android.provider.Settings;
4647
import android.util.DisplayMetrics;
4748
import android.util.Log;
4849
import android.view.Display;
@@ -57,6 +58,7 @@ of this software and associated documentation files (the "Software"), to deal
5758
import java.io.File;
5859
import java.io.FilenameFilter;
5960
import java.io.UnsupportedEncodingException;
61+
import java.lang.reflect.Field;
6062
import java.lang.reflect.InvocationTargetException;
6163
import java.lang.reflect.Method;
6264
import java.util.LinkedHashSet;
@@ -316,6 +318,7 @@ public static String getVersion() {
316318
String version = Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxActivity.getContext().getPackageName(), 0).versionName;
317319
return version;
318320
} catch(Exception e) {
321+
Log.e(TAG, "Exception: " + e.getMessage());
319322
return "";
320323
}
321324
}
@@ -325,17 +328,63 @@ public static String getBuildVersion() {
325328
int version = Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxActivity.getContext().getPackageName(), 0).versionCode;
326329
return Integer.toString(version);
327330
} catch(Exception e) {
331+
Log.e(TAG, "Exception: " + e.getMessage());
328332
return "";
329333
}
330334
}
331335

332336
public static String getCopyrightString() {
333337
return "Copyright (c) 2017";
334-
// try {
335-
// return "";
336-
// } catch(Exception e) {
337-
// return "";
338-
// }
338+
}
339+
340+
private static String capitalize(String s) {
341+
if (s == null || s.length() == 0) {
342+
return "";
343+
}
344+
char first = s.charAt(0);
345+
if (Character.isUpperCase(first)) {
346+
return s;
347+
} else {
348+
return Character.toUpperCase(first) + s.substring(1);
349+
}
350+
}
351+
352+
public static String getModelString() {
353+
try {
354+
String str = Build.MODEL;
355+
if (! Build.MODEL.startsWith(Build.MANUFACTURER)) {
356+
str = Build.MANUFACTURER + " " + Build.MODEL;
357+
}
358+
str = capitalize(str);
359+
Log.d(TAG, "Device Model: " + str);
360+
return str;
361+
} catch(Exception e) {
362+
Log.e(TAG, "Exception: " + e.getMessage());
363+
return "";
364+
}
365+
}
366+
367+
public static String getPlatformString() {
368+
try {
369+
Field[] fields = Build.VERSION_CODES.class.getFields();
370+
String str = fields[Build.VERSION.SDK_INT + 1].getName();
371+
str += " " + Build.VERSION.RELEASE;
372+
Log.d(TAG, "Platform String:" + str);
373+
return str;
374+
} catch(Exception e) {
375+
Log.e(TAG, "Exception: " + e.getMessage());
376+
return "";
377+
}
378+
}
379+
380+
public static String getDeviceID() {
381+
try {
382+
String deviceId = Settings.Secure.getString(Cocos2dxActivity.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
383+
return deviceId;
384+
} catch(Exception e) {
385+
Log.e(TAG, "Exception: " + e.getMessage());
386+
return "";
387+
}
339388
}
340389

341390
public static boolean openURL(String url) {

0 commit comments

Comments
 (0)