diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index df32464e..449fe5cc 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -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(); diff --git a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java index 1b58e804..3bce662c 100644 --- a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java @@ -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; } diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java index f409fdaf..36f03c82 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -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()); } }); diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 0d14cb1f..68cf3652 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -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!");