2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-28 20:57:42 +00:00

Fixed Android 4.1 crash

This commit is contained in:
Albert Vaca 2015-06-13 22:16:17 -07:00
parent 9a04f24de6
commit 5b694a3b3e
4 changed files with 74 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -484,7 +485,12 @@ public class Device implements BaseLink.PackageReceiver {
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationId = (int)System.currentTimeMillis(); 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(); if (pairingTimer != null) pairingTimer.cancel();
pairingTimer = new Timer(); pairingTimer = new Timer();

View File

@ -83,7 +83,13 @@ public class PingPlugin extends Plugin {
.build(); .build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 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; return true;
} }

View File

@ -29,6 +29,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -224,7 +225,13 @@ public class ShareActivity extends ActionBarActivity {
.setAutoCancel(true) .setAutoCancel(true)
.setOngoing(true) .setOngoing(true)
.setProgress(100,0,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()); final Handler progressBarHandler = new Handler(Looper.getMainLooper());
@ -288,7 +295,12 @@ public class ShareActivity extends ActionBarActivity {
final String filename = np.getString("filename"); final String filename = np.getString("filename");
builder.setContentText(res.getString(R.string.outgoing_file_text,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() { device.sendPackage(np, new Device.SendPackageStatusCallback() {
@ -302,7 +314,12 @@ public class ShareActivity extends ActionBarActivity {
@Override @Override
public void run() { public void run() {
builder.setProgress(100, progress, false); 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 @Override
public void run() { public void run() {
Resources res = getApplicationContext().getResources(); 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())) .setContentTitle(res.getString(R.string.sent_file_title, device.getName()))
.setContentText(res.getString(R.string.sent_file_text, filename)) .setContentText(res.getString(R.string.sent_file_text, filename))
.setTicker(res.getString(R.string.sent_file_title, device.getName())) .setTicker(res.getString(R.string.sent_file_title, device.getName()))
@ -324,9 +341,14 @@ public class ShareActivity extends ActionBarActivity {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (prefs.getBoolean("share_notification_preference", true)) { 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 @Override
public void run() { public void run() {
Resources res = getApplicationContext().getResources(); 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())) .setContentTitle(res.getString(R.string.sent_file_failed_title, device.getName()))
.setContentText(res.getString(R.string.sent_file_failed_text, filename)) .setContentText(res.getString(R.string.sent_file_failed_text, filename))
.setTicker(res.getString(R.string.sent_file_title, device.getName())) .setTicker(res.getString(R.string.sent_file_title, device.getName()))
@ -350,9 +372,14 @@ public class ShareActivity extends ActionBarActivity {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (prefs.getBoolean("share_notification_preference", true)) { 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());
} }
}); });

View File

@ -113,7 +113,12 @@ public class SharePlugin extends Plugin {
.setOngoing(true) .setOngoing(true)
.setProgress(100,0,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() { new Thread(new Runnable() {
@Override @Override
@ -134,7 +139,12 @@ public class SharePlugin extends Plugin {
if (progressPercentage != prevProgressPercentage) { if (progressPercentage != prevProgressPercentage) {
prevProgressPercentage = progressPercentage; prevProgressPercentage = progressPercentage;
builder.setProgress(100, (int) progressPercentage, false); 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"); //else Log.e("SharePlugin", "Infinite loop? :D");
@ -189,8 +199,12 @@ public class SharePlugin extends Plugin {
builder.setDefaults(Notification.DEFAULT_ALL); builder.setDefaults(Notification.DEFAULT_ALL);
} }
Notification notification = builder.build(); try {
notificationManager.notify(notificationId, notification); 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) { } catch (Exception e) {
Log.e("SharePlugin", "Receiver thread exception"); Log.e("SharePlugin", "Receiver thread exception");
@ -242,7 +256,12 @@ public class SharePlugin extends Plugin {
.build(); .build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 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 { } else {
Log.e("SharePlugin", "Error: Nothing attached!"); Log.e("SharePlugin", "Error: Nothing attached!");