|
@@ -17,6 +17,7 @@ import android.util.Log;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
+import androidx.core.content.ContextCompat;
|
|
|
|
|
|
import com.vpn.fastestvpnservice.R;
|
|
|
import com.vpn.fastestvpnservice.utils.WifiScanReceiver;
|
|
@@ -75,20 +76,20 @@ public class WiFiMonitorService extends Service {
|
|
|
// }
|
|
|
// }, 0, WIFI_SCAN_INTERVAL);
|
|
|
|
|
|
-// startNotification();
|
|
|
+ // registerReceiver(wifiScanReceiver, intentFilter);
|
|
|
+
|
|
|
+ startForegroundNotification();
|
|
|
|
|
|
Log.d("open wifi rec s Start", "Started onStartCommand");
|
|
|
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
- registerReceiver(wifiScanReceiver, intentFilter);
|
|
|
+ wifiScanReceiver = new WifiScanReceiver();
|
|
|
+ intentFilter = new IntentFilter();
|
|
|
+ intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
|
+
|
|
|
+ ContextCompat.registerReceiver(getApplicationContext(), wifiScanReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
|
|
|
+
|
|
|
boolean status = wifiManager.startScan();
|
|
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
- // TODO: Consider calling
|
|
|
- // ActivityCompat#requestPermissions
|
|
|
- // here to request the missing permissions, and then overriding
|
|
|
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
- // int[] grantResults)
|
|
|
- // to handle the case where the user grants the permission. See the documentation
|
|
|
- // for ActivityCompat#requestPermissions for more details.
|
|
|
return START_STICKY;
|
|
|
}
|
|
|
|
|
@@ -101,6 +102,22 @@ public class WiFiMonitorService extends Service {
|
|
|
return START_STICKY;
|
|
|
}
|
|
|
|
|
|
+ private void startForegroundNotification() {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ String channelId = "FastestVPN_Foreground_Wifi";
|
|
|
+ NotificationChannel channel = new NotificationChannel(channelId, "FastestVPN", NotificationManager.IMPORTANCE_LOW);
|
|
|
+ NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
|
|
+
|
|
|
+ notificationManager.createNotificationChannel(channel);
|
|
|
+ Notification.Builder notification = new Notification.Builder(getApplicationContext(), channelId)
|
|
|
+ .setContentTitle("Your connection is secured")
|
|
|
+ .setContentText("Auto-connect feature will automatically detect network changes as set in the app settings.")
|
|
|
+ .setColor(getApplicationContext().getResources().getColor(R.color.blue_text))
|
|
|
+ .setSmallIcon(R.drawable.ic_logo_notify);
|
|
|
+ startForeground(1, notification.build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void startNotification() {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|