This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For BLUETOOTH scans. | |
Create CBCentralManager class element and call its method for scanning Bluetooth devices. | |
Here is the function declaration | |
*/ | |
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]? = nil) | |
/* | |
For BEACONS scan. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For BLUETOOTH scans. | |
Create CBCentralManager class element and call its method for scanning Bluetooth devices. | |
Here is the function declaration | |
*/ | |
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]? = nil) | |
/* | |
For BEACONS scan. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var locationManager: CLLocationManager = { | |
let locationManager = CLLocationManager() | |
locationManager.delegate = self | |
locationManager.allowsBackgroundLocationUpdates = true | |
return locationManager | |
}() | |
var region:CLBeaconRegion { | |
let region = CLBeaconRegion(proximityUUID: uuid, identifier: identifier) | |
region.notifyEntryStateOnDisplay = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest> | |
... | |
<service ... | |
android:foregroundServiceType="location|camera|microphone" /> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun fetchUser(): User { | |
return GlobalScope.async(Dispatchers.IO) { | |
// make network call | |
}.await() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | |
@Override | |
public void onStateChanged(View view, int i) { | |
// .. | |
// your code is here | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinearLayout bottomSheet = findViewById(R.id.bottom_sheet_behavior_id); | |
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); | |
// .. | |
// here you could find all the UI views inside your bottom sheet and initialize them | |
// .. | |
// .. | |
// setting the bottom sheet callback for interacting with state changes and sliding | |
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:background="@drawable/your_bottom_sheet_background" | |
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" | |
app:behavior_hideable="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
Intent intent = new Intent(); | |
String packageName = getPackageName(); | |
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); | |
if (!pm.isIgnoringBatteryOptimizations(packageName)) { | |
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | |
intent.setData(Uri.parse("package:" + packageName)); | |
startActivity(intent); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final WifiManager wifimanager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); | |
wifimanager.registerScanResultsCallback(getMainExecutor(), new WifiManager.ScanResultsCallback() { | |
@Override | |
public void onScanResultsAvailable() { | |
List<ScanResult> results = wifimanager.getScanResults(); | |
for (ScanResult result : results) { | |
System.out.println(result.BSSID); | |
} | |
} |