Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
public void provideBluetoothMeasurement(String name,
String address,
int rssi,
byte[] scanRecord);
public void provideWifiMeasurement(List<android.net.wifi.ScanResult> scanResults);
mWifiBroadcastReceiver = new BroadcastReceiver()
{
@Override public void onReceive(Context c, Intent intent)
{
try
{
// Your code here
}
catch (Throwable e)
{
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();
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)
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);
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 NavigineReceiverExample 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")) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0,
public class AvatarView extends AppCompatImageView {
/*
* Path of them image to be clipped (to be shown)
* */
Path clipPath;
/*
* Place holder drawable (with background color and initials)
* */
@Override
protected void onDraw(Canvas canvas) {
if (shape == RECTANGLE) {
canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, borderPaint);
clipPath.addRoundRect(rectF, cornerRadius, cornerRadius, Path.Direction.CW);
} else {
canvas.drawCircle(rectF.centerX(), rectF.centerY(), (rectF.height() / 2) - borderWidth, borderPaint);
clipPath.addCircle(rectF.centerX(), rectF.centerY(), (rectF.height() / 2), Path.Direction.CW);
/*
* Set the canvas bounds here
* */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int screenWidth = MeasureSpec.getSize(widthMeasureSpec);
int screenHeight = MeasureSpec.getSize(heightMeasureSpec);
rectF.set(0, 0, screenWidth, screenHeight);
}