mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-03-13 17:50:23 +01:00
FIX: Fix find-my-phone for android 10 with notifications.
This commit is contained in:
parent
06bea85260
commit
8cfdd62eb4
@ -90,7 +90,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND4;
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.ZETIME;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.ZETIME;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID;
|
||||||
/**
|
/**
|
||||||
* Main Application class that initializes and provides access to certain things like
|
* Main Application class that initializes and provides access to certain things like
|
||||||
* logging and DB access.
|
* logging and DB access.
|
||||||
@ -211,6 +211,14 @@ public class GBApplication extends Application {
|
|||||||
notificationManager.createNotificationChannel(channel);
|
notificationManager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationChannel channelHighPr = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID );
|
||||||
|
if (channelHighPr == null) {
|
||||||
|
channelHighPr = new NotificationChannel(NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID,
|
||||||
|
getString(R.string.notification_channel_high_priority_name),
|
||||||
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
|
notificationManager.createNotificationChannel(channelHighPr);
|
||||||
|
}
|
||||||
|
|
||||||
bluetoothStateChangeReceiver = new BluetoothStateChangeReceiver();
|
bluetoothStateChangeReceiver = new BluetoothStateChangeReceiver();
|
||||||
registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -39,6 +40,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
|
|
||||||
public class FindPhoneActivity extends AbstractGBActivity {
|
public class FindPhoneActivity extends AbstractGBActivity {
|
||||||
@ -84,6 +86,9 @@ public class FindPhoneActivity extends AbstractGBActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
notificationManager.cancel( GB.NOTIFICATION_ID_PHONE_FIND );
|
||||||
|
|
||||||
vibrate();
|
vibrate();
|
||||||
playRingtone();
|
playRingtone();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import android.content.Intent;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -67,6 +68,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBMusicControlRece
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
||||||
|
|
||||||
// TODO: support option for a single reminder notification when notifications could not be delivered?
|
// TODO: support option for a single reminder notification when notifications could not be delivered?
|
||||||
@ -86,6 +88,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
private Context context;
|
private Context context;
|
||||||
private boolean autoReconnect;
|
private boolean autoReconnect;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
||||||
this.gbDevice = gbDevice;
|
this.gbDevice = gbDevice;
|
||||||
@ -170,9 +174,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
LOG.info("Got GBDeviceEventFindPhone");
|
LOG.info("Got GBDeviceEventFindPhone");
|
||||||
switch (deviceEvent.event) {
|
switch (deviceEvent.event) {
|
||||||
case START:
|
case START:
|
||||||
Intent startIntent = new Intent(getContext(), FindPhoneActivity.class);
|
handleGBDeviceEventFindPhoneStart();
|
||||||
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.startActivity(startIntent);
|
|
||||||
break;
|
break;
|
||||||
case STOP:
|
case STOP:
|
||||||
Intent intent = new Intent(FindPhoneActivity.ACTION_FOUND);
|
Intent intent = new Intent(FindPhoneActivity.ACTION_FOUND);
|
||||||
@ -183,6 +185,38 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleGBDeviceEventFindPhoneStart() {
|
||||||
|
if ( Build.VERSION.SDK_INT < 29 ) { // this could be used if app in foreground
|
||||||
|
Intent startIntent = new Intent(getContext(), FindPhoneActivity.class);
|
||||||
|
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(startIntent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handleGBDeviceEventFindPhoneStartNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleGBDeviceEventFindPhoneStartNotification() {
|
||||||
|
LOG.info("Got handleGBDeviceEventFindPhoneStartNotification");
|
||||||
|
Intent intent = new Intent(context, FindPhoneActivity.class);
|
||||||
|
|
||||||
|
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID );
|
||||||
|
notification
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setOngoing(false)
|
||||||
|
.setFullScreenIntent(pi, true)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentTitle( context.getString( R.string.find_my_phone_notification ) );
|
||||||
|
notification.setGroup("BackgroundService");
|
||||||
|
|
||||||
|
notificationManager.notify( GB.NOTIFICATION_ID_PHONE_FIND, notification.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
|
private void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for MUSIC_CONTROL");
|
LOG.info("Got event for MUSIC_CONTROL");
|
||||||
|
@ -59,6 +59,7 @@ import static nodomain.freeyourgadget.gadgetbridge.GBApplication.isRunningOreoOr
|
|||||||
public class GB {
|
public class GB {
|
||||||
|
|
||||||
public static final String NOTIFICATION_CHANNEL_ID = "gadgetbridge";
|
public static final String NOTIFICATION_CHANNEL_ID = "gadgetbridge";
|
||||||
|
public static final String NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID = "gadgetbridge_high_priority";
|
||||||
public static final String NOTIFICATION_CHANNEL_ID_TRANSFER = "gadgetbridge transfer";
|
public static final String NOTIFICATION_CHANNEL_ID_TRANSFER = "gadgetbridge transfer";
|
||||||
|
|
||||||
public static final int NOTIFICATION_ID = 1;
|
public static final int NOTIFICATION_ID = 1;
|
||||||
@ -66,6 +67,7 @@ public class GB {
|
|||||||
public static final int NOTIFICATION_ID_LOW_BATTERY = 3;
|
public static final int NOTIFICATION_ID_LOW_BATTERY = 3;
|
||||||
public static final int NOTIFICATION_ID_TRANSFER = 4;
|
public static final int NOTIFICATION_ID_TRANSFER = 4;
|
||||||
public static final int NOTIFICATION_ID_EXPORT_FAILED = 5;
|
public static final int NOTIFICATION_ID_EXPORT_FAILED = 5;
|
||||||
|
public static final int NOTIFICATION_ID_PHONE_FIND = 6;
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GB.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GB.class);
|
||||||
public static final int INFO = 1;
|
public static final int INFO = 1;
|
||||||
|
@ -267,6 +267,7 @@
|
|||||||
<string name="test">Test</string>
|
<string name="test">Test</string>
|
||||||
<string name="test_notification">Test notification</string>
|
<string name="test_notification">Test notification</string>
|
||||||
<string name="this_is_a_test_notification_from_gadgetbridge">This is a test notification from Gadgetbridge</string>
|
<string name="this_is_a_test_notification_from_gadgetbridge">This is a test notification from Gadgetbridge</string>
|
||||||
|
<string name="find_my_phone_notification">Find my phone</string>
|
||||||
<string name="bluetooth_is_not_supported_">Bluetooth is not supported.</string>
|
<string name="bluetooth_is_not_supported_">Bluetooth is not supported.</string>
|
||||||
<string name="bluetooth_is_disabled_">Bluetooth is disabled.</string>
|
<string name="bluetooth_is_disabled_">Bluetooth is disabled.</string>
|
||||||
<string name="tap_connected_device_for_app_mananger">Tap connected device for App manager</string>
|
<string name="tap_connected_device_for_app_mananger">Tap connected device for App manager</string>
|
||||||
@ -700,6 +701,7 @@
|
|||||||
<string name="devicetype_banglejs">Bangle.js</string>
|
<string name="devicetype_banglejs">Bangle.js</string>
|
||||||
<string name="choose_auto_export_location">Choose export location</string>
|
<string name="choose_auto_export_location">Choose export location</string>
|
||||||
<string name="notification_channel_name">Gadgetbridge notifications</string>
|
<string name="notification_channel_name">Gadgetbridge notifications</string>
|
||||||
|
<string name="notification_channel_high_priority_name">Gadgetbridge notifications high priority</string>
|
||||||
<string name="devicetype_amazfit_gts">Amazfit GTS</string>
|
<string name="devicetype_amazfit_gts">Amazfit GTS</string>
|
||||||
<!-- Menus on the smart device -->
|
<!-- Menus on the smart device -->
|
||||||
<string name="menuitem_shortcut_alipay">Alipay (Shortcut)</string>
|
<string name="menuitem_shortcut_alipay">Alipay (Shortcut)</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user