add json null for making sdk requests. cleanup notifications on service shutdown.

This commit is contained in:
Akinwale Ariwodola 2020-05-17 14:11:30 +01:00
parent 6b8b227af7
commit e80815cf7e
3 changed files with 18 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.os.Process; import android.os.Process;
import java.io.File; import java.io.File;
@ -126,9 +127,16 @@ public class PythonService extends Service implements Runnable {
serviceEntrypoint, pythonName, serviceEntrypoint, pythonName,
pythonHome, pythonPath, pythonHome, pythonPath,
pythonServiceArgument); pythonServiceArgument);
cleanupNotifications();
stopSelf(); stopSelf();
} }
public void cleanupNotifications() {
Context context = getApplicationContext();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
// Native part // Native part
public static native void nativeStart( public static native void nativeStart(
String androidPrivate, String androidArgument, String androidPrivate, String androidArgument,

View file

@ -481,6 +481,14 @@ public final class LbrynetService extends PythonService {
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
} }
@Override
public void cleanupNotifications() {
Context context = getApplicationContext();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
@Override @Override
public void onDestroy() { public void onDestroy() {
if (downloadReceiver != null) { if (downloadReceiver != null) {
@ -493,11 +501,7 @@ public final class LbrynetService extends PythonService {
stopServiceReceiver = null; stopServiceReceiver = null;
} }
Context context = getApplicationContext(); cleanupNotifications();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
super.onDestroy(); super.onDestroy();
serviceInstance = null; serviceInstance = null;
} }

View file

@ -353,7 +353,7 @@ public final class Utils {
if (params != null) { if (params != null) {
JSONObject requestParams = new JSONObject(); JSONObject requestParams = new JSONObject();
for (Map.Entry<String, Object> entry : params.entrySet()) { for (Map.Entry<String, Object> entry : params.entrySet()) {
requestParams.put(entry.getKey(), entry.getValue()); requestParams.put(entry.getKey(), entry.getValue() == null ? JSONObject.NULL : entry.getValue());
} }
request.put("params", requestParams); request.put("params", requestParams);
} }