Improved android networking
This commit is contained in:
parent
a533494b3a
commit
ad1844adc7
27 changed files with 568 additions and 69 deletions
|
|
@ -19,6 +19,7 @@
|
|||
package com.erroratline0.infinipaint;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
|
@ -142,4 +143,10 @@ public class InfiniPaint extends SDLActivity {
|
|||
static public void updateTextboxAndCursorPos(String str, int selectionBegin, int selectionEnd) {
|
||||
mSingleton.commandHandler.post(new InfiniPaintUpdateTextboxAndCursorPosTask(str, selectionBegin, selectionEnd));
|
||||
}
|
||||
static public void startNetworkService() {
|
||||
mSingleton.startForegroundService(new Intent(mSingleton, InfiniPaintNetworkService.class));
|
||||
}
|
||||
static public void stopNetworkService() {
|
||||
mSingleton.stopService(new Intent(mSingleton, InfiniPaintNetworkService.class));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.erroratline0.infinipaint;
|
||||
|
||||
import android.app.ForegroundServiceStartNotAllowedException;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
|
||||
public class InfiniPaintNetworkService extends Service {
|
||||
public static native void networkServiceStarted();
|
||||
public static native void networkServiceDestroyed();
|
||||
|
||||
private static final String CHANNEL_ID = "NetworkServiceChannel";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
createNotificationChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Notification notification = new Notification.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle("Online canvas")
|
||||
.setContentText("Currently online")
|
||||
.build();
|
||||
startForeground(1, notification);
|
||||
networkServiceStarted();
|
||||
// For now, don't try restarting the connection after we've been disconnected
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// We don't provide binding, so return null
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
networkServiceDestroyed();
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
NotificationChannel serviceChannel = new NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
"Network Service Channel",
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
);
|
||||
NotificationManager manager = getSystemService(NotificationManager.class);
|
||||
manager.createNotificationChannel(serviceChannel);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue