add stop action button to LBRY service notification ()

This commit is contained in:
Akinwale Ariwodola 2018-08-22 13:50:59 +01:00 committed by GitHub
parent f926dc28be
commit b99ffa0395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 3 deletions
src/main/java/io/lbry/browser

View file

@ -49,6 +49,8 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
private static final int PHONE_STATE_PERMISSION_REQ_CODE = 202;
private BroadcastReceiver stopServiceReceiver;
private BroadcastReceiver backgroundMediaReceiver;
private ReactRootView mReactRootView;
@ -86,6 +88,9 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
super.onCreate(savedInstanceState);
currentActivity = this;
// Register the stop service receiver (so that we close the activity if the user requests the service to stop)
registerStopReceiver();
// Start the daemon service if it is not started
serviceRunning = isServiceRunning(LbrynetService.class);
if (!serviceRunning) {
@ -111,6 +116,18 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
setContentView(mReactRootView);
}
private void registerStopReceiver() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(LbrynetService.ACTION_STOP_SERVICE);
stopServiceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
MainActivity.this.finish();
}
};
registerReceiver(stopServiceReceiver, intentFilter);
}
private void registerBackgroundMediaReceiver() {
// Background media receiver
IntentFilter backgroundMediaFilter = new IntentFilter();
@ -266,6 +283,12 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
if (backgroundMediaReceiver != null) {
unregisterReceiver(backgroundMediaReceiver);
backgroundMediaReceiver = null;
}
if (stopServiceReceiver != null) {
unregisterReceiver(stopServiceReceiver);
stopServiceReceiver = null;
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);