You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.1 KiB
77 lines
2.1 KiB
package dev.garrettmills.starship.hyperlink;
|
|
|
|
import android.app.Notification;
|
|
import android.app.PendingIntent;
|
|
import android.app.Service;
|
|
import android.content.Intent;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.Looper;
|
|
import android.widget.Toast;
|
|
|
|
import java.sql.Time;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
import dev.garrettmills.starship.hyperlink.relay.ServerSentRequest;
|
|
|
|
public class MessagingService extends Service {
|
|
private final Handler handler = new Handler();
|
|
private final Timer timer = new Timer();
|
|
|
|
public MessagingService() {
|
|
}
|
|
|
|
@Override
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
Intent notificationIntent = new Intent(this, MainActivity.class);
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
|
|
|
Notification notification = new Notification.Builder(this, Hyperlink.NOTIFICATION_CHANNEL)
|
|
.setContentTitle("Starship Hyperlink is Running")
|
|
.setContentText("Your text messages are being relayed to Hyperlink.")
|
|
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
|
.setContentIntent(pendingIntent)
|
|
.setTicker("ticker")
|
|
.build();
|
|
|
|
startForeground(Hyperlink.SERVICE_NOTIFICATION_ID, notification);
|
|
startConnection();
|
|
return START_STICKY;
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
timer.cancel();
|
|
}
|
|
|
|
private void startConnection() {
|
|
TimerTask task = new TimerTask() {
|
|
@Override
|
|
public void run() {
|
|
handler.post(() -> {
|
|
if ( !tick() ) {
|
|
stopSelf();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
timer.schedule(task, 0, Hyperlink.MESSAGE_TICK_POLL_INTERVAL_MS);
|
|
}
|
|
|
|
private boolean tick() {
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public IBinder onBind(Intent intent) {
|
|
return null;
|
|
}
|
|
|
|
protected void handleServerSentRequest(ServerSentRequest request) {
|
|
|
|
}
|
|
}
|