Skip to content

Instantly share code, notes, and snippets.

View MrCrambo's full-sized avatar
🏓
Win the world

mrcrambo MrCrambo

🏓
Win the world
  • Russia
View GitHub Profile
JobScheduler jobShedulerService = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobShedulerService.schedule(new JobInfo.Builder(ID, new ComponentName(context, NavigineJobService.class.getName()))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) // any network type
.setPeriodic(15 * 60 * 1000) // every 15 minutes
.setRequiresCharging(false) // if device should be charging
.build());
public class NavigineBroadcastReceiverExample extends BroadcastReceiver {
// here you need to receive some action from intent and depending on this action start service or set repeating alarm
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
try{
if (action.equals("START")) {
Intent wakeIntent = new Intent("WAKE");
wakeIntent.setClass(context, YourReceiver.class);
public class ForegroundService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String input = intent.getStringExtra("inputExtra");
createNotificationChannel();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, YourActivity.class), 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
mRttBroadcastReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent)
{
try
{
for (ScanResult scanResult: mWifiManager.getScanResults())
{
if (scanResult.is80211mcResponder())
{
RangingRequest.Builder rB = new RangingRequest.Builder();
mWifiBroadcastReceiver = new BroadcastReceiver()
{
@Override public void onReceive(Context c, Intent intent)
{
try
{
// Your code here
}
catch (Throwable e)
{
public void provideBluetoothMeasurement(String name,
String address,
int rssi,
byte[] scanRecord);
public void provideWifiMeasurement(List<android.net.wifi.ScanResult> scanResults);
/*
Initialize the NavigineSDK and load your location
*/
NavigineSDK.initialize(mContext, USER_HASH, SERVER_URL);
NavigineSDK.loadLocationInBackground(D.LOCATION_NAME, 30, mLoadListener); // Loading with Location.LoadListener callback
LocationView locationView = findViewById(R.id.locationView);
...
/*
After the location is loaded, you could set it to LocationView element
if (!mWifiScanning && timeNow > mWifiLastTime + WIFI_SLEEP_TIMEOUT)
{
if (mWifiBroadcastReceiver != null && !mWifiRegistered)
{
mContext.registerReceiver(mWifiBroadcastReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
mWifiRegistered = true;
}
if (mWifiManager.startScan())
{
public class UploadWorker extends Worker {
public UploadWorker(
@NonNull Context context,
@NonNull WorkerParameters params) {
super(context, params);
}
@Override
public Result doWork() {
public class NotificationService extends Service {
private static final int ID_SERVICE = 101;
@Nullable @Override public IBinder onBind(Intent intent) {
return null;
}
@Override public void onCreate() {
super.onCreate();