mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +00:00
Error handling
This commit is contained in:
@@ -62,7 +62,7 @@ public class DeviceHelper {
|
|||||||
//It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName().
|
//It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName().
|
||||||
public static String getDeviceName(Context context) {
|
public static String getDeviceName(Context context) {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
// Could use prefrences.contains but would need to check for empty String anyway.
|
// Could use preferences.contains but would need to check for empty String anyway.
|
||||||
String deviceName = preferences.getString(KEY_DEVICE_NAME_PREFERENCE, "");
|
String deviceName = preferences.getString(KEY_DEVICE_NAME_PREFERENCE, "");
|
||||||
if (deviceName.isEmpty()) {
|
if (deviceName.isEmpty()) {
|
||||||
if (!fetchingName) {
|
if (!fetchingName) {
|
||||||
@@ -77,10 +77,16 @@ public class DeviceHelper {
|
|||||||
private static void backgroundFetchDeviceName(final Context context) {
|
private static void backgroundFetchDeviceName(final Context context) {
|
||||||
DeviceName.with(context).request((info, error) -> {
|
DeviceName.with(context).request((info, error) -> {
|
||||||
fetchingName = false;
|
fetchingName = false;
|
||||||
|
if (error != null) {
|
||||||
|
Log.e("DeviceHelper", "Error fetching device name");
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
if (info != null) {
|
||||||
String deviceName = info.getName();
|
String deviceName = info.getName();
|
||||||
Log.i("DeviceHelper", "Got device name: " + deviceName);
|
Log.i("DeviceHelper", "Got device name: " + deviceName);
|
||||||
// Update the shared preference. Places that display the name should be listening to this change and update it
|
// Update the shared preference. Places that display the name should be listening to this change and update it
|
||||||
setDeviceName(context, deviceName);
|
setDeviceName(context, deviceName);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user