Browse Source

Initial Commit

punitkapoor-rgb 3 years ago
parent
commit
add20497a8
47 changed files with 2192 additions and 0 deletions
  1. 13 0
      .gitignore
  2. 3 0
      .idea/.gitignore
  3. 6 0
      .idea/compiler.xml
  4. 4 0
      .idea/encodings.xml
  5. 21 0
      .idea/gradle.xml
  6. 40 0
      .idea/jarRepositories.xml
  7. 6 0
      .idea/misc.xml
  8. 12 0
      .idea/runConfigurations.xml
  9. 6 0
      .idea/vcs.xml
  10. 1 0
      app/.gitignore
  11. 37 0
      app/build.gradle
  12. 21 0
      app/proguard-rules.pro
  13. 27 0
      app/src/androidTest/java/com/example/bluetoothscanning/ExampleInstrumentedTest.java
  14. 52 0
      app/src/main/AndroidManifest.xml
  15. 84 0
      app/src/main/java/com/example/bluetoothscanning/ConnectThread.java
  16. 66 0
      app/src/main/java/com/example/bluetoothscanning/DeviceListAdapter.java
  17. 851 0
      app/src/main/java/com/example/bluetoothscanning/MainActivity.java
  18. 259 0
      app/src/main/java/com/example/bluetoothscanning/WifiScanActivity.java
  19. 34 0
      app/src/main/res/drawable-v24/ic_launcher_foreground.xml
  20. 170 0
      app/src/main/res/drawable/ic_launcher_background.xml
  21. 50 0
      app/src/main/res/layout/activity_main.xml
  22. 35 0
      app/src/main/res/layout/device_adapter_view.xml
  23. 17 0
      app/src/main/res/layout/wifi_adapter_view.xml
  24. 17 0
      app/src/main/res/layout/wifi_scanned_devices.xml
  25. 5 0
      app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  26. 5 0
      app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  27. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher.png
  28. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher_round.png
  29. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher.png
  30. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher_round.png
  31. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher.png
  32. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  33. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  34. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  35. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  36. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
  37. 6 0
      app/src/main/res/values/colors.xml
  38. 3 0
      app/src/main/res/values/strings.xml
  39. 11 0
      app/src/main/res/values/styles.xml
  40. 17 0
      app/src/test/java/com/example/bluetoothscanning/ExampleUnitTest.java
  41. 30 0
      build.gradle
  42. 20 0
      gradle.properties
  43. BIN
      gradle/wrapper/gradle-wrapper.jar
  44. 6 0
      gradle/wrapper/gradle-wrapper.properties
  45. 172 0
      gradlew
  46. 84 0
      gradlew.bat
  47. 1 0
      settings.gradle

+ 13 - 0
.gitignore

@@ -0,0 +1,13 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild

+ 3 - 0
.idea/.gitignore

@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml

+ 6 - 0
.idea/compiler.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <bytecodeTargetLevel target="1.8" />
+  </component>
+</project>

+ 4 - 0
.idea/encodings.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding" addBOMForNewFiles="with NO BOM" />
+</project>

+ 21 - 0
.idea/gradle.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="GradleMigrationSettings" migrationVersion="1" />
+  <component name="GradleSettings">
+    <option name="linkedExternalProjectsSettings">
+      <GradleProjectSettings>
+        <option name="testRunner" value="PLATFORM" />
+        <option name="distributionType" value="DEFAULT_WRAPPED" />
+        <option name="externalProjectPath" value="$PROJECT_DIR$" />
+        <option name="modules">
+          <set>
+            <option value="$PROJECT_DIR$" />
+            <option value="$PROJECT_DIR$/app" />
+          </set>
+        </option>
+        <option name="resolveModulePerSourceSet" value="false" />
+        <option name="useQualifiedModuleNames" value="true" />
+      </GradleProjectSettings>
+    </option>
+  </component>
+</project>

+ 40 - 0
.idea/jarRepositories.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RemoteRepositoriesConfiguration">
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="jboss.community" />
+      <option name="name" value="JBoss Community repository" />
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="BintrayJCenter" />
+      <option name="name" value="BintrayJCenter" />
+      <option name="url" value="https://jcenter.bintray.com/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="Google" />
+      <option name="name" value="Google" />
+      <option name="url" value="https://dl.google.com/dl/android/maven2/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven" />
+      <option name="name" value="maven" />
+      <option name="url" value="https://jitpack.io" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven" />
+      <option name="name" value="maven" />
+      <option name="url" value="https://www.jitpack.io" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="MavenRepo" />
+      <option name="name" value="MavenRepo" />
+      <option name="url" value="https://repo.maven.apache.org/maven2/" />
+    </remote-repository>
+  </component>
+</project>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/classes" />
+  </component>
+</project>

+ 12 - 0
.idea/runConfigurations.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RunConfigurationProducerService">
+    <option name="ignoredProducers">
+      <set>
+        <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
+        <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
+        <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
+      </set>
+    </option>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 1 - 0
app/.gitignore

@@ -0,0 +1 @@
+/build

+ 37 - 0
app/build.gradle

@@ -0,0 +1,37 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 29
+    buildToolsVersion "29.0.0"
+    defaultConfig {
+        applicationId "com.example.bluetoothscanning"
+        minSdkVersion 15
+        targetSdkVersion 29
+        versionCode 1
+        versionName "1.0"
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+    }
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+}
+
+dependencies {
+    implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
+    implementation 'com.google.android.gms:play-services-location:17.0.0'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test:runner:1.3.0'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+    implementation 'androidx.recyclerview:recyclerview:1.1.0'
+    implementation 'android.arch.work:work-runtime:1.0.1'
+    implementation 'com.github.helios-h2020:h.core-SocialEgoNetwork:1.0.3'
+
+}

+ 21 - 0
app/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 27 - 0
app/src/androidTest/java/com/example/bluetoothscanning/ExampleInstrumentedTest.java

@@ -0,0 +1,27 @@
+package com.example.bluetoothscanning;
+
+import android.content.Context;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+    @Test
+    public void useAppContext() {
+        // Context of the app under test.
+        Context appContext = InstrumentationRegistry.getTargetContext();
+
+        assertEquals("com.example.bluetoothscanning", appContext.getPackageName());
+    }
+}

+ 52 - 0
app/src/main/AndroidManifest.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    package="com.example.bluetoothscanning">
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
+    <uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name = "android.permission.CHANGE_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"
+        tools:ignore="ProtectedPermissions" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/app_name"
+        android:roundIcon="@mipmap/ic_launcher_round"
+        android:supportsRtl="true"
+        android:theme="@style/AppTheme"
+        tools:ignore="GoogleAppIndexingWarning">
+        <activity android:name=".MainActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".DeviceListAdapter">
+
+    </activity>
+        <activity android:name=".WifiScanActivity">
+
+        </activity>
+
+
+    </application>
+
+</manifest>

+ 84 - 0
app/src/main/java/com/example/bluetoothscanning/ConnectThread.java

@@ -0,0 +1,84 @@
+package com.example.bluetoothscanning;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothSocket;
+import android.content.Context;
+import android.telephony.TelephonyManager;
+
+import androidx.core.content.ContextCompat;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.UUID;
+
+public class ConnectThread extends Thread
+{
+    private final BluetoothSocket mmSocket;
+    BluetoothAdapter mBluetoothAdapter;
+
+    private final UUID WELL_KNOWN_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
+
+    public ConnectThread(BluetoothDevice device, BluetoothAdapter bluetoothAdapter)
+    {
+        // Use a temporary object that is later assigned to mmSocket,because
+        // mmSocket is final
+        BluetoothSocket tmp = null;
+        mBluetoothAdapter= bluetoothAdapter;
+       // mBluetoothAdapter= BluetoothAdapter.getDefaultAdapter();
+        // Get a BluetoothSocket to connect with the given BluetoothDevice
+        try
+        {
+
+
+           tmp = device.createRfcommSocketToServiceRecord(WELL_KNOWN_UUID);
+            //This is the trick
+            Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
+            tmp = (BluetoothSocket) m.invoke(device, 1);
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+        mmSocket = tmp;
+    }
+
+    public void run()
+    {
+       // DebugLog.i(TAG, "Trying to connect...");
+        // Cancel discovery because it will slow down the connection
+       mBluetoothAdapter.cancelDiscovery();
+
+        try
+        {
+            // Connect the device through the socket. This will block
+            // until it succeeds or throws an exception
+            mmSocket.connect();
+
+
+        } catch (IOException connectException)
+        {
+            // Unable to connect; close the socket and get out
+           // DebugLog.e(TAG, "Fail to connect!", connectException);
+            try
+            {
+                mmSocket.close();
+            } catch (IOException closeException)
+            {
+              //  DebugLog.e(TAG, "Fail to close connection", closeException);
+            }
+            return;
+        }
+    }
+
+    /** Will cancel an in-progress connection, and close the socket */
+    public void cancel()
+    {
+        try
+        {
+            mmSocket.close();
+        } catch (IOException e)
+        {
+        }
+    }
+}

+ 66 - 0
app/src/main/java/com/example/bluetoothscanning/DeviceListAdapter.java

@@ -0,0 +1,66 @@
+package com.example.bluetoothscanning;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.os.Build;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import static androidx.constraintlayout.widget.Constraints.TAG;
+
+public class DeviceListAdapter extends ArrayAdapter<BluetoothDevice>{
+
+private LayoutInflater mLayoutInflater;
+private ArrayList<BluetoothDevice> mDevices;
+private int  mViewResourceId;
+String currentTimeStamp;
+int rssi_value;
+public DeviceListAdapter(Context context, int tvResourceId, ArrayList<BluetoothDevice> devices, int rssi){
+        super(context, tvResourceId,devices);
+        this.mDevices = devices;
+        this.rssi_value=rssi;
+        mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        mViewResourceId = tvResourceId;
+        }
+
+public View getView(int position, View convertView, ViewGroup parent) {
+        convertView = mLayoutInflater.inflate(mViewResourceId, null);
+    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    String currentDateTime = dateFormat.format(new Date());
+    int rssiValue= rssi_value;
+    int count=0;
+        BluetoothDevice device = mDevices.get(position);
+
+        if (device != null) {
+        TextView deviceName = (TextView) convertView.findViewById(R.id.tvDeviceName);
+        TextView deviceAdress = (TextView) convertView.findViewById(R.id.tvDeviceAddress);
+         TextView timeStamp=(TextView) convertView.findViewById(R.id.tvTimeStamp);
+        if (deviceName != null) {
+        deviceName.setText(device.getName());
+        }
+        if (deviceAdress != null) {
+        deviceAdress.setText(device.getAddress());
+        }
+        if(timeStamp!=null){
+            timeStamp.setText(currentDateTime);
+        }
+
+        }
+
+        return convertView;
+        }
+
+
+}

+ 851 - 0
app/src/main/java/com/example/bluetoothscanning/MainActivity.java

@@ -0,0 +1,851 @@
+package com.example.bluetoothscanning;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothClass;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothSocket;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.location.Address;
+import android.location.Criteria;
+import android.location.Geocoder;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.media.MediaScannerConnection;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.ParcelUuid;
+import android.os.PowerManager;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import androidx.annotation.RequiresApi;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+
+import com.google.android.gms.location.LocationServices;
+import com.google.android.gms.tasks.OnSuccessListener;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.UUID;
+
+import eu.h2020.helios_social.core.contextualegonetwork.ContextualEgoNetwork;
+import eu.h2020.helios_social.core.contextualegonetwork.Node;
+
+import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+
+public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, SensorEventListener {
+    private static final int REQUEST_LOCATION = 1;
+    Button onOffButton, wifiOnOffButton;
+    Button EnableDiscoverable_on_off;
+    ListView lvNewDevices;
+    private static final String TAG = "Mainactivity";
+    public ArrayList<BluetoothDevice> mBTDevices = new ArrayList<>();
+    public ArrayList<BluetoothDevice> mproximityBluetoothDevice = new ArrayList<>();
+    public ArrayList<String> maddressValue = new ArrayList<>();
+    DeviceListAdapter mDeviceListAdapter;
+    BluetoothAdapter mBluetoothAdapter;
+    int rssi;
+    Handler handler;
+    String currentDateTime;
+    PowerManager.WakeLock wakeLock;  //Declaration of Instance variable.
+    int frequncy = 0;
+    private boolean waitingForBonding;
+    Runnable r;
+    Sensor accelerometer, gyrometer, magnometer, banometer, light, temperature, gravity;
+    LocationManager locManager;
+    double latitude;
+    double longitude;
+    String addressValue;
+
+    private final BroadcastReceiver bondStateChanged = new BroadcastReceiver() {
+        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
+                BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+                //3 cases
+                //1.already a bond
+                if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
+                    Log.d(TAG, "bondStateChanged: BOND_BONDED");
+
+                }
+                //2.Creating a bond
+                if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDING) {
+                    Log.d(TAG, "bondStateChanged: BOND_BONDING");
+                    bluetoothDevice.createBond();
+                }
+                //3.the bond is broken
+                if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_NONE) {
+                    Log.d(TAG, "bondStateChanged: BOND_NONE");
+
+
+                }
+            }
+
+        }
+    };
+
+    public final BroadcastReceiver discoverUnpairedDevices = new BroadcastReceiver() {
+        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+        public void onReceive(Context context, Intent intent) {
+
+            final String action = intent.getAction();
+            Log.d(TAG, "OnReceive: Action found");
+            if (action.equals(BluetoothDevice.ACTION_FOUND)) {
+
+                BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+                rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
+
+
+                @SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                currentDateTime = dateFormat.format(new Date());
+                BluetoothClass bluetoothClass = bluetoothDevice.getBluetoothClass();
+                if (bluetoothClass.getDeviceClass() == BluetoothClass.Device.PHONE_SMART) {
+
+
+                    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+                        if (checkSelfPermission(ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+                            return;
+                        }
+                    }
+                    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,
+                            500.0f, locationListener);
+                    Location location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+                    if (location != null) {
+                        latitude = location.getLatitude();
+                        longitude = location.getLongitude();
+                         addressValue=getAddress(latitude,longitude);
+                         maddressValue.add(addressValue);
+                    }
+
+                    ContextualEgoNetwork cen = ContextualEgoNetwork.createOrLoad("", "user_00001", null);
+                    Node user1 = cen.getEgo();
+                    mBTDevices.add(bluetoothDevice);
+
+                    if(mBTDevices.contains(bluetoothDevice) && maddressValue.contains(addressValue))
+                    {
+                        frequncy= Collections.frequency(mBTDevices, bluetoothDevice);
+
+                        if(frequncy > 1)
+                        {
+
+                            mproximityBluetoothDevice.add(bluetoothDevice);
+
+                           /* Boolean isBonded = false;
+                            try {
+                                isBonded = createBond(bluetoothDevice);
+                                if(isBonded)
+                                {
+                                    Log.i("Log","Paired");
+                                }
+                            } catch (Exception e)
+                            {
+                                e.printStackTrace();
+                            }*/
+
+                            Node user2= cen.getOrCreateNode("user-0002",currentDateTime);
+                            Node user3= cen.getOrCreateNode("user-0003",currentDateTime);
+                            Node user4= cen.getOrCreateNode("user-0004",currentDateTime);
+                            eu.h2020.helios_social.core.contextualegonetwork.Context context1= cen.getOrCreateContext("Test context");
+                            context1.getOrAddEdge(user1,user2);
+                            context1.getOrAddEdge(user1,user3);
+                            context1.getOrAddEdge(user1,user4);
+                            cen.save();
+
+                            //activityTimer();
+                        }
+                       // chooserDialog();
+
+                    }
+
+
+                    WriteBtn(bluetoothDevice.getAddress(), rssi, currentDateTime,frequncy,addressValue);
+
+
+                }
+
+
+                Log.d(TAG, "OnReceive:" + bluetoothDevice.getName() + " " + bluetoothDevice.getAddress() + "" + rssi);
+                mDeviceListAdapter = new DeviceListAdapter(context, R.layout.device_adapter_view, mBTDevices, rssi);
+                lvNewDevices.setAdapter(mDeviceListAdapter);
+
+
+            }
+
+        }
+    };
+
+
+    public void chooserDialog(){
+        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
+        alertDialogBuilder.setMessage("We have few devices in your proximity, would you like to make a connection?");
+                alertDialogBuilder.setPositiveButton("yes",
+                        new DialogInterface.OnClickListener() {
+                            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+                            @Override
+                            public void onClick(DialogInterface arg0, int arg1) {
+                              stopRepeatingTask();
+                                int counter=0;
+                                for(counter=0; counter < mproximityBluetoothDevice.size();counter++){
+                                    mproximityBluetoothDevice.get(counter).createBond();
+                                }
+                                //activityTimer();
+                            }
+                        });
+
+        alertDialogBuilder.setNegativeButton("No",
+                new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        finish();
+                    }
+                });
+
+        AlertDialog alertDialog = alertDialogBuilder.create();
+        alertDialog.show();
+    }
+    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+  /*  public void createBond(BluetoothDevice btDevice) {
+       *//* try {
+            Log.d(TAG, "Start Pairing...");
+
+        waitingForBonding = true;
+
+        Method m = btDevice.getClass()
+                .getMethod("createBond", (Class[]) null);
+        m.invoke(btDevice, (Object[]) null);
+
+            Log.d(TAG, "Pairing finished.");
+    } catch (Exception e) {
+        Log.e(TAG, e.getMessage());
+    }*//*
+        *//*try {
+            Method m = btDevice.getClass().getMethod("createBond",(Class[]) null);
+          m.invoke(btDevice,(Object[]) null );
+            *//**//*Log.d("pairDevice()", "Start Pairing...");
+            Method m = btDevice.getClass().getMethod("createBond", (Class[]) null);
+            m.invoke(btDevice, (Object[]) null);
+            Log.d("pairDevice()", "Pairing finished.");*//**//*
+        } catch (Exception e) {
+            Log.e("pairDevice()", e.getMessage());
+        }*//*
+
+    }
+*/
+    public boolean createBond(BluetoothDevice btDevice)
+            throws Exception
+    {
+        Class class1 = Class.forName("android.bluetooth.BluetoothDevice");
+        Method createBondMethod = class1.getMethod("createBond");
+        Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
+        return returnValue.booleanValue();
+    }
+
+    public String getAddress(double lat, double lng) {
+        String add="";
+        Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
+        try {
+            List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
+            Address obj = addresses.get(0);
+            add = obj.getAddressLine(0);
+            add = add + "\n" + obj.getCountryName();
+            add = add + "\n" + obj.getCountryCode();
+            add = add + "\n" + obj.getAdminArea();
+            add = add + "\n" + obj.getPostalCode();
+            add = add + "\n" + obj.getSubAdminArea();
+            add = add + "\n" + obj.getLocality();
+            add = add + "\n" + obj.getSubThoroughfare();
+
+            Log.v("IGA", "Address" + add);
+            // Toast.makeText(this, "Address=>" + add,
+            // Toast.LENGTH_SHORT).show();
+
+            // TennisAppActivity.showDialog(add);
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
+        }
+        return add;
+    }
+    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+    public void WriteBtn(String address, int rssi, String currentDateTime, int frequncy,String addressValue) {
+        try {
+            File file = new File(this.getExternalFilesDir(null), "BluetoothScannedDevice.txt");
+            FileOutputStream fileOutput = new FileOutputStream(file, true);
+            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutput);
+            outputStreamWriter.write("Address : " + address);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("DB :" + rssi);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("TimeStamp:" + currentDateTime);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("Frequency:" + frequncy);
+            outputStreamWriter.write("\n\n");
+            outputStreamWriter.write("Location:" + addressValue);
+            outputStreamWriter.write("\n\n");
+            outputStreamWriter.flush();
+            fileOutput.getFD().sync();
+            outputStreamWriter.close();
+            MediaScannerConnection.scanFile(
+                    this,
+                    new String[]{file.getAbsolutePath()},
+                    null,
+                    null);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    private final BroadcastReceiver bluetoothStateBroadcastReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (action.equals(mBluetoothAdapter.ACTION_STATE_CHANGED)) {
+                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, mBluetoothAdapter.ERROR);
+
+
+                switch (state) {
+                    case BluetoothAdapter.STATE_OFF:
+                       stopRepeatingTask();
+                        Log.d(TAG, "onReceive: STATE OFF");
+                    case BluetoothAdapter.STATE_TURNING_OFF:
+                        Log.d(TAG, "onReceive: STATE TURNING OFF");
+                    case BluetoothAdapter.STATE_ON:
+                       startRepeatingTask();
+                        Log.d(TAG, "onReceive: STATE ON");
+                    case BluetoothAdapter.STATE_TURNING_ON:
+                        Log.d(TAG, "onReceive: STATE TURNING ON");
+
+                }
+            }
+        }
+    };
+
+    private final BroadcastReceiver bluetoothDiscoverableBroadcastReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (action.equals(mBluetoothAdapter.ACTION_SCAN_MODE_CHANGED)) {
+                int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, mBluetoothAdapter.ERROR);
+
+
+                switch (mode) {
+                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+                        Log.d(TAG, "bluetoothDiscoverableBroadcastReceiver: Discoverable Enabled");
+                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
+                        Log.d(TAG, "bluetoothDiscoverableBroadcastReceiver: Discoverablity Enabled. Able to receive connections.");
+                    case BluetoothAdapter.SCAN_MODE_NONE:
+                        Log.d(TAG, "bluetoothDiscoverableBroadcastReceiver: Discoverablity Disabled. Not Able to receive connections.");
+                    case BluetoothAdapter.STATE_CONNECTING:
+                        Log.d(TAG, "bluetoothDiscoverableBroadcastReceiver:Connecting...");
+                    case BluetoothAdapter.STATE_CONNECTED:
+                        Log.d(TAG, "bluetoothDiscoverableBroadcastReceiver:Connected...");
+
+                }
+            }
+        }
+    };
+
+    @SuppressLint("InvalidWakeLockTag")
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_main);
+        onOffButton = findViewById(R.id.OnOffButton);
+        wifiOnOffButton= findViewById(R.id.wifiScanning);
+        EnableDiscoverable_on_off = findViewById(R.id.EnableDiscoverable_on_off);
+        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        Method getUuidsMethod = null;
+        try {
+            getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
+        } catch (NoSuchMethodException e) {
+            e.printStackTrace();
+        }
+
+        ParcelUuid[] uuids = new ParcelUuid[0];
+        try {
+            uuids = (ParcelUuid[]) getUuidsMethod.invoke(mBluetoothAdapter, null);
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        } catch (InvocationTargetException e) {
+            e.printStackTrace();
+        }
+
+        /*for (ParcelUuid uuid: uuids) {
+            Log.d(TAG, "UUID: " + uuid.getUuid().toString());
+        }*/
+        lvNewDevices = findViewById(R.id.lvNewDevices);
+        handler = new Handler();
+        checkWritePermission();
+        checkBTPermission();
+        ActivityCompat.requestPermissions( this,
+                new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
+        PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+        wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
+                | PowerManager.ON_AFTER_RELEASE, "Wake Lock");
+        wakeLock.acquire();
+        wakeLock.setReferenceCounted(false);
+
+        lvNewDevices.setOnItemClickListener(MainActivity.this);
+
+        onOffButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Log.d(TAG, "Enabling/Disabling bluetooth");
+
+                enableDisableBT();
+            }
+        });
+
+         wifiOnOffButton.setOnClickListener(new View.OnClickListener() {
+             @Override
+             public void onClick(View view) {
+                 Log.d(TAG, "Enabling/Disabling WIFI");
+                 Toast.makeText(MainActivity.this, "you have choose to scan through wifi", Toast.LENGTH_LONG).show();
+                 Intent wifiIntent= new Intent(MainActivity.this, WifiScanActivity.class);
+                 startActivity(wifiIntent);
+
+             }
+         });
+
+        // use a linear layout manage
+        Log.d(TAG,"Initializing sensor services");
+        SensorManager sensorManager;
+        sensorManager=(SensorManager) getSystemService(Context.SENSOR_SERVICE);
+        assert sensorManager != null;
+        accelerometer= sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+        if(accelerometer!=null){
+          sensorManager.registerListener(MainActivity.this,accelerometer,SensorManager.SENSOR_DELAY_NORMAL);
+          Log.d(TAG,"Registered accelerometer listener");
+            }
+       else{
+          Log.d(TAG,"Accelerometer sensor is not supported");
+           }
+        gyrometer= sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
+        if(gyrometer!=null){
+            sensorManager.registerListener(MainActivity.this,gyrometer,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered gyrometer listener");
+        }
+        else{
+            Log.d(TAG,"Gyrometer sensor is not supported");
+        }
+
+        magnometer= sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
+        if(magnometer!=null){
+            sensorManager.registerListener(MainActivity.this,magnometer,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered magnometer listener");
+        }
+        else{
+            Log.d(TAG,"Magnometer sensor is not supported");
+        }
+
+        banometer= sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
+        if(banometer!=null){
+            sensorManager.registerListener(MainActivity.this,banometer,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered banometer listener");
+        }
+        else{
+            Log.d(TAG,"banometer sensor is not supported");
+        }
+
+        light=sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
+        if(light!=null){
+            sensorManager.registerListener(MainActivity.this,light,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered Light Sensor");
+        }
+        else{
+            Log.d(TAG,"Light sensor is not supported");
+
+        }
+
+        temperature = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
+        if(temperature!=null){
+            sensorManager.registerListener(MainActivity.this,light,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered Temperature Sensor");
+        }
+        else{
+            Log.d(TAG,"Temperature sensor is not supported");
+
+        }
+        gravity = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
+        if(temperature!=null){
+            sensorManager.registerListener(MainActivity.this,gravity,SensorManager.SENSOR_DELAY_NORMAL);
+            Log.d(TAG,"Registered gravity Sensor");
+        }
+        else{
+            Log.d(TAG,"gravity sensor is not supported");
+
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        stopRepeatingTask();
+        stopHandler();
+    }
+
+    @Override
+    protected void onDestroy() {
+        Log.d(TAG, "onDestroy called");
+
+        super.onDestroy();
+        unregisterReceiver(bluetoothStateBroadcastReceiver);
+        unregisterReceiver(bluetoothDiscoverableBroadcastReceiver);
+        unregisterReceiver(discoverUnpairedDevices);
+        unregisterReceiver(bondStateChanged);
+
+    }
+
+
+    public void enableDisableBT() {
+        if (mBluetoothAdapter == null) {
+            Log.d(TAG, "EnableDiabled: Does not have bluetooth capabalities");
+        }
+        if (!mBluetoothAdapter.isEnabled()) {
+            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+            startActivity(enableIntent);
+
+            IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+            registerReceiver(bluetoothStateBroadcastReceiver, BTIntent);
+
+        }
+        if (mBluetoothAdapter.isEnabled()) {
+            mBluetoothAdapter.disable();
+            IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+            registerReceiver(bluetoothStateBroadcastReceiver, BTIntent);
+        }
+    }
+
+    public void btnEnableDisable_Discoverable(View view) {
+        Log.d(TAG, "btnEnableDisable_Discoverable: Making device discoverable for 300 seconds");
+
+        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
+        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
+        startActivity(discoverableIntent);
+
+        IntentFilter discoverableConnectionIntent = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
+        registerReceiver(bluetoothDiscoverableBroadcastReceiver, discoverableConnectionIntent);
+
+
+    }
+
+    Runnable mStatusChecker = new Runnable() {
+        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+        @Override
+        public void run() {
+            try {
+
+                if (mBluetoothAdapter.isDiscovering()) {
+                    mBluetoothAdapter.cancelDiscovery();
+                    Log.d(TAG, "btnDiscover: Cancel Discovery");
+
+                    mBluetoothAdapter.startDiscovery();
+
+                }
+
+                if (!mBluetoothAdapter.isDiscovering()) {
+                    mBluetoothAdapter.startDiscovery();
+
+                }
+                int count =0;
+                while(mproximityBluetoothDevice.size()>count){
+
+                    BluetoothDevice btdevice= mproximityBluetoothDevice.get(count);
+                  ConnectThread ct = new ConnectThread(btdevice,mBluetoothAdapter);
+                  ct.start();
+                    count++;
+                }
+                IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
+                registerReceiver(discoverUnpairedDevices, discoverDevicesIntent);
+
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+
+                handler.postDelayed(mStatusChecker, 1*60*1000);
+            }
+        }
+    };
+
+
+    void startRepeatingTask() {
+        mStatusChecker.run();
+    }
+
+    void stopRepeatingTask() {
+        handler.removeCallbacks(mStatusChecker);
+    }
+
+    private void activityTimer() {
+
+        handler = new Handler();
+        r = new Runnable() {
+
+
+            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+            @Override
+            public void run() {
+                // TODO Auto-generated method stub
+                //    Toast.makeText(context, "user is inactive from last 5 minutes",Toast.LENGTH_SHORT).show();
+                if (mBluetoothAdapter.isDiscovering()) {
+                    mBluetoothAdapter.cancelDiscovery();
+                    Log.d(TAG, "btnDiscover: Cancel Discovery");
+
+                    mBluetoothAdapter.startDiscovery();
+
+                }
+
+                if (!mBluetoothAdapter.isDiscovering()) {
+                    mBluetoothAdapter.startDiscovery();
+
+                }
+                IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
+                registerReceiver(discoverUnpairedDevices, discoverDevicesIntent);
+            }
+        };
+        startHandler();
+    }
+    private void stopHandler() {
+        handler.removeCallbacks(r);
+    }
+
+    private void startHandler() {
+        handler.postDelayed(r, 1*60 * 1000); //for 5 minutes
+    }
+
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    private void checkBTPermission() {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            int permissionCHeck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
+            permissionCHeck += this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
+
+            if (permissionCHeck != 0) {
+                this.requestPermissions(new String[]{ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}, 1001);
+            } else {
+                Log.d(TAG, "checkPersmisions::No need to check");
+            }
+        }
+
+    }
+
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    private void checkWritePermission() {
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            int permissionCHeck = this.checkSelfPermission("Manifest.permission.WRITE_EXTERNAL_STORAGE");
+            permissionCHeck += this.checkSelfPermission("Manifest.permission.READ_EXTERNAL_STORAGE");
+
+            if (permissionCHeck != 0) {
+                this.requestPermissions(new String[]{ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}, 1);
+            } else {
+                Log.d(TAG, "checkPersmisions::No need to check");
+            }
+        }
+    }
+
+
+    @Override
+    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+
+        mBluetoothAdapter.cancelDiscovery();
+
+
+        Log.d(TAG, "YOu clicked the device");
+        String deviceName = mBTDevices.get(i).getName();
+        String deviceAddress = mBTDevices.get(i).getAddress();
+
+        Log.d(TAG, "Device Name" + deviceName);
+        Log.d(TAG, "Device Address" + deviceAddress);
+
+        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
+            Log.d(TAG, "Trying to pair with" + deviceName);
+            try {
+                Log.d(TAG, "Start Pairing... with: " + mBTDevices.get(i).getName());
+
+                mBTDevices.get(i).createBond();
+
+
+            } catch (Exception e) {
+                Log.e(TAG, Objects.requireNonNull(e.getMessage()));
+            }
+
+        }
+    }
+
+
+
+    @Override
+    public void onSensorChanged(SensorEvent sensorEvent) {
+        Sensor sensor= sensorEvent.sensor;
+        @SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String currentDateTime = dateFormat.format(new Date());
+        if(sensor.getType()==Sensor.TYPE_ACCELEROMETER){
+            Log.d(TAG,"ACCELEROMETER " + "X:" + sensorEvent.values[0] + "Y:"+sensorEvent.values[1] + "Z:" +sensorEvent.values[2]);
+
+          WriteSensorData("Accelerometer.txt",sensorEvent.values[0],sensorEvent.values[1],sensorEvent.values[2],currentDateTime);
+        }
+        else if(sensor.getType()==Sensor.TYPE_GYROSCOPE){
+            Log.d(TAG,"GYROMETER " + "X:" + sensorEvent.values[0]+"Y:"+sensorEvent.values[1]+ "Z:" +sensorEvent.values[2]);
+
+            WriteSensorData("Gyrometer.txt",sensorEvent.values[0],sensorEvent.values[1],sensorEvent.values[2],currentDateTime);
+
+        }
+        else if(sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD){
+            Log.d(TAG,"Magnometer " + "X:" + sensorEvent.values[0]+"Y:"+sensorEvent.values[1]+ "Z:" +sensorEvent.values[2]);
+
+            WriteSensorData("Magnometer.txt",sensorEvent.values[0],sensorEvent.values[1],sensorEvent.values[2],currentDateTime);
+
+        }
+        else if(sensor.getType()==Sensor.TYPE_LIGHT){
+            Log.d(TAG,"LIGHT " + sensorEvent.values[0]);
+            WriteSensorData("Light.txt",sensorEvent.values[0],0,0,currentDateTime);
+
+        }
+
+        else if(sensor.getType()== Sensor.TYPE_AMBIENT_TEMPERATURE){
+            Log.d(TAG,"TEMPERATURE " + sensorEvent.values[0]);
+            WriteSensorData("Temperature.txt",sensorEvent.values[0],0,0,currentDateTime);
+
+        }
+        else if(sensor.getType()== Sensor.TYPE_PRESSURE){
+            Log.d(TAG,"BANOMETER " + sensorEvent.values[0]);
+
+            WriteSensorData("Banometer.txt",sensorEvent.values[0],0,0,currentDateTime);
+
+        }
+        else if(sensor.getType()== Sensor.TYPE_GRAVITY) {
+            Log.d(TAG,"GRAVITY " + sensorEvent.values[0]);
+
+            WriteSensorData("Gravity.txt",sensorEvent.values[0],0,0,currentDateTime);
+
+        }
+    }
+    public void WriteSensorData(String name, float x, float y, float z,String currentDateTime) {
+
+
+        try {
+            File file = new File(this.getExternalFilesDir(null), name);
+            FileOutputStream fileOutput = new FileOutputStream(file, true);
+            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutput);
+            if(x!=0){
+                outputStreamWriter.write("X:" + x);
+            }
+            if(y!=0){
+                outputStreamWriter.append(" , ");
+                outputStreamWriter.write("Y:"+ y);
+                outputStreamWriter.append(" , ");
+
+            }
+            if(z!=0){
+                outputStreamWriter.write("Z:" + z);
+            }
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("Timestamp:" + currentDateTime);
+            outputStreamWriter.write("\n\n");
+            outputStreamWriter.flush();
+            fileOutput.getFD().sync();
+            outputStreamWriter.close();
+            MediaScannerConnection.scanFile(
+                    this,
+                    new String[]{file.getAbsolutePath()},
+                    null,
+                    null);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int i) {
+
+    }
+
+    private final LocationListener locationListener = new LocationListener() {
+
+        public void onLocationChanged(Location location) {
+
+           // updateWithNewLocation(location);
+
+            Toast.makeText(
+                    getBaseContext(),
+                    "Location changed: Lat: " + location.getLatitude() + " Lng: "
+                            + location.getLongitude(), Toast.LENGTH_SHORT).show();
+            String longitude = "Longitude: " + location.getLongitude();
+            Log.v(TAG, longitude);
+            String latitude = "Latitude: " + location.getLatitude();
+            Log.v(TAG, latitude);
+        }
+
+        public void onProviderDisabled(String provider) {
+            updateWithNewLocation(null);
+        }
+
+        public void onProviderEnabled(String provider) {
+        }
+
+        public void onStatusChanged(String provider, int status, Bundle extras) {
+        }
+    };
+
+    private void updateWithNewLocation(Location location) {
+       // TextView myLocationText = (TextView) findViewById(R.id.text);
+        String latLongString = "";
+        if (location != null) {
+            double lat = location.getLatitude();
+            double lng = location.getLongitude();
+            latLongString = "Lat:" + lat + "\nLong:" + lng;
+        } else {
+            latLongString = "No location found";
+        }
+
+    }
+
+    public void btnDiscover(View view)
+    {
+       //  activityTimer();
+    }
+}
+
+

+ 259 - 0
app/src/main/java/com/example/bluetoothscanning/WifiScanActivity.java

@@ -0,0 +1,259 @@
+package com.example.bluetoothscanning;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.ListActivity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.media.MediaScannerConnection;
+import android.net.wifi.ScanResult;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.PowerManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+import androidx.core.app.ActivityCompat;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+import static androidx.constraintlayout.widget.Constraints.TAG;
+
+public class WifiScanActivity extends ListActivity {
+
+
+    private final int MY_PERMISSIONS_ACCESS_COARSE_LOCATION = 1;
+
+
+    Button wifiTurnOnOff;
+    Handler handler;
+    WifiManager mainWifiObj;
+ WifiScanReceiver  wifiReciever;
+     ListView list;
+     String[] wifis;
+     String[] filtered;
+     String currentDateTime;
+    private Context context;
+    Calendar calendar;
+     String SSid;
+     String address ;
+     String key_management;
+     String strength;
+     String timestamp;
+    PowerManager.WakeLock wakeLock;  //Declaration of Instance variable.
+
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    @SuppressLint("InvalidWakeLockTag")
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.wifi_scanned_devices);
+        list = getListView();
+        handler = new Handler();
+        this.context = this;
+        calendar=Calendar.getInstance();
+        wifiTurnOnOff = findViewById(R.id.WIFIOnOff);
+        mainWifiObj = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+        wifiReciever = new WifiScanReceiver();
+        checkWritePermission();
+        checkWifiPermission();
+        PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+        wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
+                | PowerManager.ON_AFTER_RELEASE, "Wake Lock");
+        wakeLock.acquire();
+        if (!mainWifiObj.isWifiEnabled())
+        {
+            mainWifiObj.setWifiEnabled(true);
+        }
+
+        wifiTurnOnOff.setOnClickListener(new View.OnClickListener() {
+            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+            @Override
+            public void onClick(View view) {
+                if (ActivityCompat.checkSelfPermission(WifiScanActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+                    ActivityCompat.requestPermissions(
+                            WifiScanActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_ACCESS_COARSE_LOCATION);
+                       startRepeatingTask();
+                } else {
+                    startRepeatingTask();
+                }
+            }
+
+        });
+
+    }
+ Runnable mStatusChecker = new Runnable() {
+        @SuppressLint("InvalidWakeLockTag")
+        @Override
+        public void run() {
+            try {
+                @SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                currentDateTime = dateFormat.format(new Date());
+                mainWifiObj.startScan();
+                registerReceiver(wifiReciever,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+                //  updateStatus(); //this function can change value of mInterval.
+            } finally {
+                // 100% guarantee that this always happens, even if
+                // your update method throws an exception
+                handler.postDelayed(mStatusChecker, 2*60*1000);
+            }
+        }
+    };
+
+@SuppressLint("InvalidWakeLockTag")
+private void wakeUpLock(){
+
+}
+    void startRepeatingTask() {
+        mStatusChecker.run();
+    }
+
+    void stopRepeatingTask() {
+        handler.removeCallbacks(mStatusChecker);
+    }
+
+
+    @Override
+    protected void onResume() {
+        //  startRepeatingTask();
+        super.onResume();
+    }
+
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        stopRepeatingTask();
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+
+        stopRepeatingTask();
+        unregisterReceiver(wifiReciever);
+
+    }
+
+    class WifiScanReceiver extends  BroadcastReceiver {
+        public void onReceive(Context context, Intent intent) {
+
+            List<ScanResult> wifiScanList = mainWifiObj.getScanResults();
+            wifis = new String[wifiScanList.size()];
+            for (int i = 0; i < wifiScanList.size(); i++) {
+                wifis[i] = ((wifiScanList.get(i)).toString());
+            }
+            filtered = new String[wifiScanList.size()];
+
+
+
+            int counter = 0;
+            for (String eachWifi : wifis) {
+
+                String[] temp = eachWifi.split(",");
+
+                filtered[counter] = temp[0].substring(5).trim()+"\n" + temp[1].substring(6).trim() +"\n"+ temp[2].substring(12).trim()+"\n" + temp[3].substring(6).trim()+"\n" +currentDateTime;//0->SSID, 2->Key Management 3-> Strength
+                SSid=temp[0].substring(5).trim();
+                address =temp[1].substring(5).trim();
+               key_management= temp[2].substring(12).trim();
+                strength = temp[3].substring(6).trim();
+                timestamp= currentDateTime;
+
+                WriteBtn(SSid,address,key_management,strength,timestamp);
+                counter++;
+
+
+            }
+          list.setAdapter(new ArrayAdapter<String>(context.getApplicationContext(),android.R.layout.simple_list_item_1, filtered));
+
+
+        }
+        }
+
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    private void checkWifiPermission(){
+
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            int permissionCHeck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
+            permissionCHeck += this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
+
+            if (permissionCHeck != 0) {
+                this.requestPermissions(new String[]{ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}, 1001);
+
+            } else {
+                Log.d(TAG, "checkPersmisions::No need to check");
+
+            }
+        }
+    }
+
+    public void WriteBtn(String ssid, String address, String key_management, String strength, String timestamp) {
+
+
+        try {
+            File file = new File(context.getExternalFilesDir(null), "WifiScannedDevices.txt");
+            FileOutputStream fileOutput = new FileOutputStream(file, true);
+            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutput);
+            outputStreamWriter.write("SSID : " + ssid);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("MAC : " + address);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("Key Management :" + key_management);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("Strength:" + strength);
+            outputStreamWriter.append(" , ");
+            outputStreamWriter.write("TimeStamp:" + timestamp);
+            outputStreamWriter.append(" , ");
+           // outputStreamWriter.write("Frequency:" + frequncy);
+            outputStreamWriter.write("\n\n");
+            outputStreamWriter.flush();
+            fileOutput.getFD().sync();
+            outputStreamWriter.close();
+            MediaScannerConnection.scanFile(
+                    context,
+                    new String[]{file.getAbsolutePath()},
+                    null,
+                    null);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
+
+    @RequiresApi(api = Build.VERSION_CODES.M)
+    public void checkWritePermission() {
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            int permissionCHeck = this.checkSelfPermission("Manifest.permission.WRITE_EXTERNAL_STORAGE");
+            permissionCHeck += this.checkSelfPermission("Manifest.permission.READ_EXTERNAL_STORAGE");
+
+            if (permissionCHeck != 0) {
+                this.requestPermissions(new String[]{ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}, 1);
+            } else {
+               Log.d(TAG, "checkPersmisions::No need to check");
+            }
+        }
+    }
+
+
+}

File diff suppressed because it is too large
+ 34 - 0
app/src/main/res/drawable-v24/ic_launcher_foreground.xml


+ 170 - 0
app/src/main/res/drawable/ic_launcher_background.xml

@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="108dp"
+    android:height="108dp"
+    android:viewportWidth="108"
+    android:viewportHeight="108">
+    <path
+        android:fillColor="#008577"
+        android:pathData="M0,0h108v108h-108z" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M9,0L9,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,0L19,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M29,0L29,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M39,0L39,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M49,0L49,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M59,0L59,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M69,0L69,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M79,0L79,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M89,0L89,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M99,0L99,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,9L108,9"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,19L108,19"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,29L108,29"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,39L108,39"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,49L108,49"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,59L108,59"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,69L108,69"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,79L108,79"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,89L108,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,99L108,99"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,29L89,29"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,39L89,39"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,49L89,49"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,59L89,59"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,69L89,69"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,79L89,79"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M29,19L29,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M39,19L39,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M49,19L49,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M59,19L59,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M69,19L69,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M79,19L79,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+</vector>

+ 50 - 0
app/src/main/res/layout/activity_main.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".MainActivity">
+<LinearLayout
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="horizontal">
+    <Button android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        tools:ignore="MissingConstraints"
+        android:text="ON/OFF"
+        android:id="@+id/OnOffButton">
+
+    </Button>
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="160dp"
+        android:id="@+id/wifiScanning"
+        android:text="WIFI Scanning"
+        />
+</LinearLayout>
+
+
+
+    <Button android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        tools:ignore="MissingConstraints"
+        android:text="Enable Discoverable"
+        android:id="@+id/EnableDiscoverable_on_off"
+        android:onClick="btnEnableDisable_Discoverable">
+
+    </Button>
+    <Button
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        tools:ignore="MissingConstraints"
+        android:text="Discover"
+        android:id="@+id/btnFindUnpairedDevices"
+        android:onClick="btnDiscover"/>
+    <ListView
+        android:id="@+id/lvNewDevices"
+        android:layout_width="match_parent"
+        android:layout_height="631dp"
+        tools:ignore="MissingConstraints" />
+</LinearLayout>

+ 35 - 0
app/src/main/res/layout/device_adapter_view.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+
+        android:layout_height="wrap_content"
+        android:layout_width="match_parent"
+        android:id="@+id/tvDeviceName"
+        android:textSize="15sp">
+
+    </TextView>
+    <TextView
+
+        android:layout_height="wrap_content"
+        android:layout_width="match_parent"
+        android:id="@+id/tvDeviceAddress"
+        android:textSize="15sp">
+
+    </TextView>
+
+    <TextView
+
+        android:layout_height="wrap_content"
+        android:layout_width="match_parent"
+        android:id="@+id/tvTimeStamp"
+        android:textSize="15sp">
+
+    </TextView>
+
+
+
+</LinearLayout>

+ 17 - 0
app/src/main/res/layout/wifi_adapter_view.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/list_value"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:padding="10dip"
+        android:textSize="16dip"
+        android:textStyle="bold"
+        android:textColor="@android:color/holo_blue_dark"/>
+
+
+</LinearLayout>

+ 17 - 0
app/src/main/res/layout/wifi_scanned_devices.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <Button
+        android:id = "@+id/WIFIOnOff"
+        android:layout_width = "match_parent"
+        android:layout_height = "50dp"
+        android:layout_gravity = "bottom"
+        android:text = "Scan WiFi" />
+
+    <ListView
+        android:id="@android:id/list"
+        android:layout_width = "match_parent"
+        android:layout_height = "match_parent" />
+
+</LinearLayout>

+ 5 - 0
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+    <background android:drawable="@drawable/ic_launcher_background" />
+    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>

+ 5 - 0
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+    <background android:drawable="@drawable/ic_launcher_background" />
+    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>

BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png


+ 6 - 0
app/src/main/res/values/colors.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="colorPrimary">#008577</color>
+    <color name="colorPrimaryDark">#00574B</color>
+    <color name="colorAccent">#D81B60</color>
+</resources>

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">BluetoothScanning</string>
+</resources>

+ 11 - 0
app/src/main/res/values/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+        <item name="colorPrimary">@color/colorPrimary</item>
+        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
+        <item name="colorAccent">@color/colorAccent</item>
+    </style>
+
+</resources>

+ 17 - 0
app/src/test/java/com/example/bluetoothscanning/ExampleUnitTest.java

@@ -0,0 +1,17 @@
+package com.example.bluetoothscanning;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+public class ExampleUnitTest {
+    @Test
+    public void addition_isCorrect() {
+        assertEquals(4, 2 + 2);
+    }
+}

+ 30 - 0
build.gradle

@@ -0,0 +1,30 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+    repositories {
+        google()
+
+        jcenter()
+
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:3.4.1'
+
+        // NOTE: Do not place your application dependencies here; they belong
+        // in the individual module build.gradle files
+    }
+}
+
+allprojects {
+    repositories {
+        google()
+        jcenter()
+        maven {
+            url 'https://www.jitpack.io' }
+
+    }
+}
+
+task clean(type: Delete) {
+    delete rootProject.buildDir
+}

+ 20 - 0
gradle.properties

@@ -0,0 +1,20 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+

BIN
gradle/wrapper/gradle-wrapper.jar


+ 6 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,6 @@
+#Mon Oct 12 16:48:25 BST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

+ 172 - 0
gradlew

@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+    echo "$*"
+}
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Escape application args
+save () {
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+    echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+  cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"

+ 84 - 0
gradlew.bat

@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 1 - 0
settings.gradle

@@ -0,0 +1 @@
+include ':app'