Browse Source

Define the channel for the notification, which requires using

NotificationCompat, which I decided to do using "AndroidX".
Anyways, this builds, but I don't know if it works.
sigsegv_dump
Greg Alexander 3 years ago
parent
commit
9b451c9b29
  1. 3
      app/build.gradle
  2. 49
      app/src/main/java/org/galexander/sshd/SimpleSSHDService.java
  3. 2
      gradle.properties

3
app/build.gradle

@ -36,3 +36,6 @@ android {
}
}
}
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}

49
app/src/main/java/org/galexander/sshd/SimpleSSHDService.java

@ -1,12 +1,16 @@
package org.galexander.sshd;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.Context;
import android.os.Build;
import android.os.IBinder;
import android.widget.RemoteViews;
import androidx.core.app.NotificationCompat;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@ -62,28 +66,47 @@ public class SimpleSSHDService extends Service {
private void do_foreground() {
foregrounded = Prefs.get_foreground();
if (foregrounded) {
Notification n = new Notification(
R.drawable.notification_icon,
"SimpleSSHD", 0);
n.tickerText = "SimpleSSHD";
n.contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, SimpleSSHD.class),
PendingIntent.FLAG_UPDATE_CURRENT);
create_notification_channel();
n.contentView = new RemoteViews(getPackageName(),
RemoteViews rv = new RemoteViews(getPackageName(),
R.layout.notification);
/* for some reason icon cannot be defined in xml: */
n.contentView.setImageViewResource(R.id.n_icon,
R.drawable.icon);
n.contentView.setTextViewText(R.id.n_text,
rv.setImageViewResource(R.id.n_icon, R.drawable.icon);
rv.setTextViewText(R.id.n_text,
"SimpleSSHD listening on " +
SimpleSSHD.get_ip(false) +
":" + Prefs.get_port());
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SimpleSSHD.class),
PendingIntent.FLAG_UPDATE_CURRENT);
Notification n = new NotificationCompat.Builder(
this, "main")
.setSmallIcon(R.drawable.notification_icon)
.setTicker("SimpleSSHD")
.setContent(rv)
.setContentIntent(pi)
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setLocalOnly(true)
.setVisibility(
NotificationCompat.VISIBILITY_PUBLIC)
.build();
startForeground(1, n);
}
}
private void create_notification_channel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel nc = new NotificationChannel(
"main", "SimpleSSHD",
NotificationManager.IMPORTANCE_LOW);
nc.enableLights(false);
nc.enableVibration(false);
nc.setSound(null, null);
getSystemService(NotificationManager.class)
.createNotificationChannel(nc);
}
}
public static boolean is_started() {
return (sshd_pid != 0);
}

2
gradle.properties

@ -0,0 +1,2 @@
android.useAndroidX=true
android.enableJetifier=true
Loading…
Cancel
Save