Bring this app (badly) into 2024
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.mridang.speedo;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
@ -25,7 +26,7 @@ import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
@ -43,6 +44,10 @@ public class TrafficService extends Service {
|
||||
* The identifier if the component that open from the settings activity
|
||||
*/
|
||||
private static final String CMP = "com.android.settings.Settings$DataUsageSummaryActivity";
|
||||
/**
|
||||
* Notification channel ID
|
||||
*/
|
||||
private static final String CHANNEL_ID = "network_speed";
|
||||
/**
|
||||
* The instance of the handler that updates the notification
|
||||
*/
|
||||
@ -91,9 +96,11 @@ public class TrafficService extends Service {
|
||||
super.onCreate();
|
||||
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
createNotificationChannel();
|
||||
|
||||
Intent ittSettings = new Intent();
|
||||
ittSettings.setComponent(new ComponentName("com.android.settings", CMP));
|
||||
PendingIntent pitSettings = PendingIntent.getActivity(this, 0, ittSettings, 0);
|
||||
PendingIntent pitSettings = PendingIntent.getActivity(this, 0, ittSettings, PendingIntent.FLAG_IMMUTABLE);
|
||||
notBuilder = new NotificationCompat.Builder(this);
|
||||
notBuilder.setSmallIcon(R.drawable.wkb000);
|
||||
notBuilder.setContentIntent(pitSettings);
|
||||
@ -103,6 +110,7 @@ public class TrafficService extends Service {
|
||||
notBuilder.setPriority(Integer.MAX_VALUE);
|
||||
notBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE);
|
||||
notBuilder.setLocalOnly(true);
|
||||
notBuilder.setChannelId(CHANNEL_ID);
|
||||
setColor(settings.getInt("color", Color.TRANSPARENT));
|
||||
visibilityPublic(settings.getBoolean("lockscreen", true));
|
||||
|
||||
@ -388,4 +396,20 @@ public class TrafficService extends Service {
|
||||
return TrafficService.this;
|
||||
}
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
// Create the NotificationChannel, but only on API 26+ because
|
||||
// the NotificationChannel class is not in the Support Library.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = getString(R.string.channel_name);
|
||||
String description = getString(R.string.channel_description);
|
||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
|
||||
channel.setDescription(description);
|
||||
// Register the channel with the system. You can't change the importance
|
||||
// or other notification behaviors after this.
|
||||
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user