2022-11-06 04:41:39 +01:00
|
|
|
package com.beemdevelopment.aegis.services;
|
|
|
|
|
2023-12-27 17:45:28 +01:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.PendingIntent;
|
2022-11-06 04:41:39 +01:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.service.quicksettings.Tile;
|
|
|
|
import android.service.quicksettings.TileService;
|
|
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
|
|
|
import com.beemdevelopment.aegis.ui.MainActivity;
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
|
|
public class LaunchScannerTileService extends TileService {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartListening() {
|
|
|
|
super.onStartListening();
|
|
|
|
Tile tile = getQsTile();
|
2023-09-07 23:51:01 +02:00
|
|
|
if (tile != null) {
|
|
|
|
tile.setState(Tile.STATE_INACTIVE);
|
|
|
|
tile.updateTile();
|
|
|
|
}
|
2022-11-06 04:41:39 +01:00
|
|
|
}
|
|
|
|
|
2023-12-27 17:45:28 +01:00
|
|
|
@SuppressLint("StartActivityAndCollapseDeprecated")
|
2022-11-06 04:41:39 +01:00
|
|
|
@Override
|
|
|
|
public void onClick() {
|
|
|
|
super.onClick();
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
intent.putExtra("action", "scan");
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
intent.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
2023-12-27 17:45:28 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
|
|
int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, flags);
|
|
|
|
startActivityAndCollapse(pendingIntent);
|
|
|
|
} else {
|
|
|
|
startActivityAndCollapse(intent);
|
|
|
|
}
|
2022-11-06 04:41:39 +01:00
|
|
|
}
|
2023-12-27 17:45:28 +01:00
|
|
|
}
|