Skip to content

Instantly share code, notes, and snippets.

@iblinov65apps
Created April 3, 2018 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iblinov65apps/ee2da410aee5af6cc5968e0329aa3707 to your computer and use it in GitHub Desktop.
Save iblinov65apps/ee2da410aee5af6cc5968e0329aa3707 to your computer and use it in GitHub Desktop.
Phone info provider
package ru.alexfitness.data.core;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import javax.inject.Inject;
class DeviceInfoProviderImpl implements DeviceInfoProvider {
private final Context context;
@Inject
DeviceInfoProviderImpl(Context context) {
this.context = context;
}
@SuppressLint("HardwareIds")
@Override
public String getImei() {
ContentResolver contentResolver = context.getContentResolver();
return Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID);
}
@Nullable
@Override
public String getModel() {
return Build.MODEL;
}
@Nullable
@Override
public String getOs() {
return "Android " + Build.VERSION.RELEASE;
}
@Nullable
@Override
public Integer getDimensionX() {
return getDisplayMetrics().widthPixels;
}
@Nullable
@Override
public Integer getDimensionY() {
return getDisplayMetrics().heightPixels;
}
private DisplayMetrics getDisplayMetrics() {
return context.getResources().getDisplayMetrics();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment