mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-25 17:17:32 +01:00
Added quit button to Service notification, removed unneccessary ACTION_STOP form Service
This commit is contained in:
parent
ebf4c73e02
commit
8e69723931
@ -51,5 +51,6 @@
|
|||||||
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
|
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver android:name=".StopServiceReceiver"/>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -31,8 +31,6 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
|
|
||||||
public static final String ACTION_START
|
public static final String ACTION_START
|
||||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start";
|
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start";
|
||||||
public static final String ACTION_STOP
|
|
||||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.stop";
|
|
||||||
public static final String ACTION_NOTIFICATION_GENERIC
|
public static final String ACTION_NOTIFICATION_GENERIC
|
||||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_generic";
|
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_generic";
|
||||||
public static final String ACTION_NOTIFICATION_SMS
|
public static final String ACTION_NOTIFICATION_SMS
|
||||||
@ -60,7 +58,7 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
|
||||||
if (!intent.getAction().equals(ACTION_START) && !intent.getAction().equals(ACTION_STOP) && mBtSocketIoThread == null) {
|
if (!intent.getAction().equals(ACTION_START) && mBtSocketIoThread == null) {
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,11 +69,15 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
|
||||||
notificationIntent, 0);
|
notificationIntent, 0);
|
||||||
|
|
||||||
|
Intent stopIntent = new Intent(this, StopServiceReceiver.class);
|
||||||
|
PendingIntent pendingIntentStop = PendingIntent.getBroadcast(this, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
Notification notification = new NotificationCompat.Builder(this)
|
Notification notification = new NotificationCompat.Builder(this)
|
||||||
.setContentTitle("Gadgetbridge")
|
.setContentTitle("Gadgetbridge")
|
||||||
.setTicker("Gadgetbridge Running")
|
.setTicker("Gadgetbridge Running")
|
||||||
.setContentText("Gadgetbrige Running")
|
.setContentText("Gadgetbrige Running")
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
|
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Quit", pendingIntentStop)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setOngoing(true).build();
|
.setOngoing(true).build();
|
||||||
|
|
||||||
@ -113,23 +115,6 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
startForeground(1, notification); //FIXME: don't hardcode id
|
startForeground(1, notification); //FIXME: don't hardcode id
|
||||||
}
|
}
|
||||||
} else if (intent.getAction().equals(ACTION_STOP)) {
|
|
||||||
try {
|
|
||||||
mBtSocketIoThread.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
|
|
||||||
mBtSocket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
mBtSocket = null;
|
|
||||||
mBtSocketIoThread = null;
|
|
||||||
|
|
||||||
stopForeground(true);
|
|
||||||
stopSelf();
|
|
||||||
} else if (intent.getAction().equals(ACTION_NOTIFICATION_GENERIC)) {
|
} else if (intent.getAction().equals(ACTION_NOTIFICATION_GENERIC)) {
|
||||||
String title = intent.getStringExtra("notification_title");
|
String title = intent.getStringExtra("notification_title");
|
||||||
String body = intent.getStringExtra("notification_body");
|
String body = intent.getStringExtra("notification_body");
|
||||||
@ -163,6 +148,20 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
if (mBtSocketIoThread != null) {
|
||||||
|
try {
|
||||||
|
mBtSocketIoThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mBtSocket != null) {
|
||||||
|
try {
|
||||||
|
mBtSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -298,4 +297,4 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
public class StopServiceReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Intent stopIntent = new Intent(context, BluetoothCommunicationService.class);
|
||||||
|
context.stopService(stopIntent);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user