@@ -234,7 +234,7 @@ private void notifyCoinsReceived(@Nullable final Address from, @Nonnull final Bi
234
234
notification .setNumber (notificationCount == 1 ? 0 : notificationCount );
235
235
notification .setWhen (System .currentTimeMillis ());
236
236
notification .setSound (Uri .parse ("android.resource://" + getPackageName () + "/" + R .raw .coins_received ));
237
- nm .notify (NOTIFICATION_ID_COINS_RECEIVED , notification .getNotification ());
237
+ nm .notify (NOTIFICATION_ID_COINS_RECEIVED , notification .build ());
238
238
}
239
239
240
240
private final class PeerConnectivityListener extends AbstractPeerEventListener implements OnSharedPreferenceChangeListener
@@ -287,25 +287,31 @@ private void changed(final int numPeers)
287
287
@ Override
288
288
public void run ()
289
289
{
290
- final boolean connectivityNotification = prefs .getBoolean (Constants .PREFS_KEY_CONNECTIVITY_NOTIFICATION , false );
291
-
292
- if (!connectivityNotification || numPeers == 0 )
293
- {
294
- nm .cancel (NOTIFICATION_ID_CONNECTED );
295
- }
296
- else
297
- {
298
- final NotificationCompat .Builder notification = new NotificationCompat .Builder (BlockchainServiceImpl .this );
299
- notification .setSmallIcon (R .drawable .stat_sys_peers , numPeers > 4 ? 4 : numPeers );
300
- notification .setContentTitle (getString (R .string .app_name ));
301
- notification .setContentText (getString (R .string .notification_peers_connected_msg , numPeers ));
302
- notification .setContentIntent (PendingIntent .getActivity (BlockchainServiceImpl .this , 0 , new Intent (BlockchainServiceImpl .this ,
303
- WalletActivity .class ), 0 ));
304
- notification .setWhen (System .currentTimeMillis ());
305
- notification .setOngoing (true );
306
- nm .notify (NOTIFICATION_ID_CONNECTED , notification .getNotification ());
307
- }
308
-
290
+ if (numPeers == 0 )
291
+ {
292
+ nm .cancel (NOTIFICATION_ID_CONNECTED );
293
+ }
294
+ else
295
+ {
296
+ final NotificationCompat .Builder notification = new NotificationCompat .Builder (BlockchainServiceImpl .this )
297
+ .setSmallIcon (R .drawable .stat_sys_peers , numPeers > 4 ? 4 : numPeers )
298
+ .setContentTitle (getString (R .string .app_name ))
299
+ .setContentText (getString (R .string .notification_peers_connected_msg , numPeers ))
300
+ .setContentIntent (PendingIntent .getActivity (BlockchainServiceImpl .this , 0 , new Intent (BlockchainServiceImpl .this ,
301
+ WalletActivity .class ), 0 ))
302
+ .setWhen (System .currentTimeMillis ())
303
+ .setOngoing (true )
304
+ /*
305
+ * These calls are ignored by the support library for
306
+ * pre-4.1 devices.
307
+ */
308
+ .addAction (R .drawable .ic_action_clear ,
309
+ getString (R .string .wallet_options_disconnect ),
310
+ PendingIntent .getService (BlockchainServiceImpl .this , 0 ,
311
+ new Intent (BlockchainServiceImpl .this , BlockchainServiceImpl .class )
312
+ .setAction (BlockchainService .ACTION_STOP_SERVICE ), 0 ));
313
+ nm .notify (NOTIFICATION_ID_CONNECTED , notification .build ());
314
+ }
309
315
// send broadcast
310
316
sendBroadcastPeerState (numPeers );
311
317
}
@@ -727,6 +733,12 @@ else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action))
727
733
log .info ("peergroup not available, not broadcasting transaction " + tx .getHashAsString ());
728
734
}
729
735
}
736
+ else if (BlockchainService .ACTION_STOP_SERVICE .equals (action ))
737
+ {
738
+ log .info ("stopping self" );
739
+ // deliberate stop command, so don't schedule restart
740
+ stopSelf ();
741
+ }
730
742
731
743
return START_NOT_STICKY ;
732
744
}
0 commit comments