mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-28 12:47:43 +00:00
Fixed Android 4.1 crash
This commit is contained in:
parent
9a04f24de6
commit
5b694a3b3e
@ -28,6 +28,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -484,7 +485,12 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
|
||||
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationId = (int)System.currentTimeMillis();
|
||||
notificationManager.notify(notificationId, noti);
|
||||
try {
|
||||
notificationManager.notify(notificationId, noti);
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
if (pairingTimer != null) pairingTimer.cancel();
|
||||
pairingTimer = new Timer();
|
||||
|
@ -83,7 +83,13 @@ public class PingPlugin extends Plugin {
|
||||
.build();
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(id, noti);
|
||||
try {
|
||||
notificationManager.notify(id, noti);
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -224,7 +225,13 @@ public class ShareActivity extends ActionBarActivity {
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(true)
|
||||
.setProgress(100,0,true);
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
final Handler progressBarHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@ -288,7 +295,12 @@ public class ShareActivity extends ActionBarActivity {
|
||||
final String filename = np.getString("filename");
|
||||
|
||||
builder.setContentText(res.getString(R.string.outgoing_file_text,filename));
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
device.sendPackage(np, new Device.SendPackageStatusCallback() {
|
||||
|
||||
@ -302,7 +314,12 @@ public class ShareActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void run() {
|
||||
builder.setProgress(100, progress, false);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -314,7 +331,7 @@ public class ShareActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void run() {
|
||||
Resources res = getApplicationContext().getResources();
|
||||
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(getApplicationContext())
|
||||
NotificationCompat.Builder anotherBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
.setContentTitle(res.getString(R.string.sent_file_title, device.getName()))
|
||||
.setContentText(res.getString(R.string.sent_file_text, filename))
|
||||
.setTicker(res.getString(R.string.sent_file_title, device.getName()))
|
||||
@ -324,9 +341,14 @@ public class ShareActivity extends ActionBarActivity {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
if (prefs.getBoolean("share_notification_preference", true)) {
|
||||
builder1.setDefaults(Notification.DEFAULT_ALL);
|
||||
anotherBuilder.setDefaults(Notification.DEFAULT_ALL);
|
||||
}
|
||||
try {
|
||||
notificationManager.notify(notificationId,anotherBuilder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
notificationManager.notify(notificationId, builder1.build());
|
||||
}
|
||||
});
|
||||
|
||||
@ -340,7 +362,7 @@ public class ShareActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void run() {
|
||||
Resources res = getApplicationContext().getResources();
|
||||
NotificationCompat.Builder builder2 = new NotificationCompat.Builder(getApplicationContext())
|
||||
NotificationCompat.Builder anotherBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
.setContentTitle(res.getString(R.string.sent_file_failed_title, device.getName()))
|
||||
.setContentText(res.getString(R.string.sent_file_failed_text, filename))
|
||||
.setTicker(res.getString(R.string.sent_file_title, device.getName()))
|
||||
@ -350,9 +372,14 @@ public class ShareActivity extends ActionBarActivity {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
if (prefs.getBoolean("share_notification_preference", true)) {
|
||||
builder2.setDefaults(Notification.DEFAULT_ALL);
|
||||
anotherBuilder.setDefaults(Notification.DEFAULT_ALL);
|
||||
}
|
||||
try {
|
||||
notificationManager.notify(notificationId,anotherBuilder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
notificationManager.notify(notificationId, builder2.build());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -113,7 +113,12 @@ public class SharePlugin extends Plugin {
|
||||
.setOngoing(true)
|
||||
.setProgress(100,0,true);
|
||||
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
@ -134,7 +139,12 @@ public class SharePlugin extends Plugin {
|
||||
if (progressPercentage != prevProgressPercentage) {
|
||||
prevProgressPercentage = progressPercentage;
|
||||
builder.setProgress(100, (int) progressPercentage, false);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
}
|
||||
}
|
||||
//else Log.e("SharePlugin", "Infinite loop? :D");
|
||||
@ -189,8 +199,12 @@ public class SharePlugin extends Plugin {
|
||||
builder.setDefaults(Notification.DEFAULT_ALL);
|
||||
}
|
||||
|
||||
Notification notification = builder.build();
|
||||
notificationManager.notify(notificationId, notification);
|
||||
try {
|
||||
notificationManager.notify(notificationId,builder.build());
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("SharePlugin", "Receiver thread exception");
|
||||
@ -242,7 +256,12 @@ public class SharePlugin extends Plugin {
|
||||
.build();
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify((int)System.currentTimeMillis(), noti);
|
||||
try {
|
||||
notificationManager.notify((int)System.currentTimeMillis(), noti);
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e("SharePlugin", "Error: Nothing attached!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user