Created
March 15, 2019 00:39
-
-
Save dario61081/49529f5bc28183a0bc0584958d7c144c to your computer and use it in GitHub Desktop.
Configuraciones base
This file contains hidden or 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 apps.com.py.jesuitas; | |
import android.Manifest; | |
import android.content.Context; | |
import android.content.pm.PackageManager; | |
import android.support.v4.app.ActivityCompat; | |
import android.telephony.TelephonyManager; | |
import android.util.Log; | |
import com.iamhabib.easy_preference.EasyPreference; | |
import org.apache.commons.lang.StringUtils; | |
public class Configuraciones { | |
public static final String URL_VALIDAR_IMEI = "/api/v1/cobrador/imei/"; | |
private static final String URL_BASE = "http://192.168.0.1:8000"; | |
private static final String URL_CONTEXT = "RESTApi"; | |
private static final String TAG = "Configuraciones"; | |
public static String getUrl(Context context, String... args) { | |
String host = EasyPreference.with(context).getString("host", URL_BASE + "/" + Configuraciones.URL_CONTEXT); | |
Log.w(TAG, "getUrl: " + host); | |
return host + StringUtils.join(args); | |
} | |
/** | |
* Establecer la url base | |
* @param context contexto | |
* @param url ruta con puerto | |
*/ | |
public static void setBaseUrl(Context context, String url) { | |
EasyPreference.with(context).addString("host", url).save(); | |
} | |
/** | |
* Leer la url base | |
* @param context contexto | |
* @return cadena url base | |
*/ | |
public static String getBaseUrl(Context context){ | |
return EasyPreference.with(context).getString("host", URL_BASE); | |
} | |
/** | |
* Traer informacion del imei del dispositivo | |
* @param context contexto | |
* @return cadena imei del dispositivo o identificador unico | |
*/ | |
public static String getImei(Context context) { | |
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { | |
return manager.getDeviceId() != null ? manager.getDeviceId() : "-"; | |
} | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment