anotherim/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java

39 lines
1.2 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.utils;
import android.Manifest;
2018-05-12 15:23:37 +00:00
import android.annotation.SuppressLint;
2014-10-22 16:38:44 +00:00
import android.content.Context;
2015-02-16 09:06:09 +00:00
import android.content.pm.PackageManager;
2014-10-22 16:38:44 +00:00
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
2014-10-22 16:38:44 +00:00
import android.provider.ContactsContract.Profile;
2018-05-12 15:23:37 +00:00
import android.provider.Settings;
2014-10-22 16:38:44 +00:00
public class PhoneHelper {
2018-05-12 15:23:37 +00:00
@SuppressLint("HardwareIds")
public static String getAndroidId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
public static Uri getProfilePictureUri(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
return null;
}
final String[] projection = new String[]{Profile._ID, Profile.PHOTO_URI};
final Cursor cursor;
try {
cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
2018-03-12 14:59:35 +00:00
} catch (Throwable e) {
return null;
}
if (cursor == null) {
2014-10-22 16:38:44 +00:00
return null;
}
final String uri = cursor.moveToFirst() ? cursor.getString(1) : null;
cursor.close();
return uri == null ? null : Uri.parse(uri);
2014-10-22 16:38:44 +00:00
}
}