Created
January 27, 2021 10:59
-
-
Save amixpal/3caa75e6e145bd5b37f391ec4cf377d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app.fitme.trainer.utils.common; | |
import android.content.Context; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
import android.os.Build; | |
import android.util.Log; | |
import com.google.android.gms.common.ConnectionResult; | |
import com.google.android.gms.common.GoogleApiAvailability; | |
import java.util.HashMap; | |
import java.util.TimeZone; | |
import java.util.UUID; | |
/** | |
* Created by Paly on 8/15/18. | |
* TalentHound | |
* amix.pal@gmail.com | |
*/ | |
public class MetadataUtils { | |
public static final String TAG = "MetadataUtils"; | |
public static String getManufacturer(Context context) { | |
String mfg = "unknown"; | |
try { | |
final Class<?> buildClass = Build.class; | |
mfg = (String) buildClass.getField("MANUFACTURER").get(null); //$NON-NLS-1$ | |
mfg = mfg + " " + buildClass.getField("MODEL").get(null); | |
mfg = mfg + " " + buildClass.getField("PRODUCT").get(null); | |
} catch (Exception e) { | |
//LogUtils.logException(TAG, e); | |
} | |
HashMap<String, String> params = new HashMap<>(); | |
try { | |
params.put("ModelInfo", mfg); | |
} catch (Exception e) { | |
// LogUtils.logException(TAG, e); | |
} | |
try { | |
params.put("RootStatus", String.valueOf(RootUtils.isDeviceRooted())); | |
} catch (Exception e) { | |
//LogUtils.logException(TAG, e); | |
} | |
return params.toString(); | |
} | |
public static int getAppVersion(Context context) { | |
try { | |
PackageInfo packageInfo = context.getPackageManager() | |
.getPackageInfo(context.getPackageName(), 0); | |
return packageInfo.versionCode; | |
} catch (PackageManager.NameNotFoundException e) { | |
throw new RuntimeException("Could not get package name: " + e); | |
} | |
} | |
public static String getDeviceId(Context context) { | |
String androidDeviceId = getAndroidDeviceId(context); | |
if (androidDeviceId == null) | |
androidDeviceId = UUID.randomUUID().toString(); | |
return androidDeviceId; | |
} | |
public static String getAndroidDeviceId(Context context) { | |
final String INVALID_ANDROID_ID = "9774d56d682e549c"; | |
final String androidId = android.provider.Settings.Secure.getString( | |
context.getContentResolver(), | |
android.provider.Settings.Secure.ANDROID_ID); | |
if (androidId == null | |
|| androidId.toLowerCase().equals(INVALID_ANDROID_ID)) { | |
return null; | |
} | |
return androidId; | |
} | |
public static String timeZone() { | |
TimeZone tz = TimeZone.getDefault(); | |
return tz.getID(); | |
} | |
public static boolean checkPlayServices(Context context) { | |
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); | |
int resultCode = apiAvailability.isGooglePlayServicesAvailable(context); | |
if (resultCode != ConnectionResult.SUCCESS) { | |
if (apiAvailability.isUserResolvableError(resultCode)) { | |
Log.i(TAG, "Install Google Play Service"); | |
} else { | |
Log.i(TAG, "This device is not supported."); | |
} | |
return false; | |
} | |
return true; | |
} | |
public static String getMobileOsVersion(){ | |
return String.valueOf(Build.VERSION.SDK_INT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment