24-03-2023
This commit is contained in:
		
							parent
							
								
									a4f3ec0890
								
							
						
					
					
						commit
						28d9fe5e59
					
				
							
								
								
									
										1
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <project version="4"> | <project version="4"> | ||||||
|  |   <component name="GradleMigrationSettings" migrationVersion="1" /> | ||||||
|   <component name="GradleSettings"> |   <component name="GradleSettings"> | ||||||
|     <option name="linkedExternalProjectsSettings"> |     <option name="linkedExternalProjectsSettings"> | ||||||
|       <GradleProjectSettings> |       <GradleProjectSettings> | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="VcsDirectoryMappings"> | ||||||
|  |     <mapping directory="" vcs="Git" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
| @ -30,10 +30,10 @@ | |||||||
|         android:theme="@style/Theme.BeaconDemo" |         android:theme="@style/Theme.BeaconDemo" | ||||||
|         tools:targetApi="31"> |         tools:targetApi="31"> | ||||||
|         <activity |         <activity | ||||||
|             android:name=".DetailActivity" |             android:name=".Activity.DetailActivity" | ||||||
|             android:exported="false" /> |             android:exported="false" /> | ||||||
|         <activity |         <activity | ||||||
|             android:name=".MainActivity" |             android:name=".Activity.MainActivity" | ||||||
|             android:exported="true"> |             android:exported="true"> | ||||||
|             <intent-filter> |             <intent-filter> | ||||||
|                 <action android:name="android.intent.action.MAIN" /> |                 <action android:name="android.intent.action.MAIN" /> | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.example.beacondemo; | package com.example.beacondemo.Activity; | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AppCompatActivity; | import androidx.appcompat.app.AppCompatActivity; | ||||||
| 
 | 
 | ||||||
| @ -7,6 +7,7 @@ import android.util.Log; | |||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
| 
 | 
 | ||||||
|  | import com.example.beacondemo.R; | ||||||
| import com.minew.beaconplus.sdk.MTCentralManager; | import com.minew.beaconplus.sdk.MTCentralManager; | ||||||
| import com.minew.beaconplus.sdk.MTConnectionHandler; | import com.minew.beaconplus.sdk.MTConnectionHandler; | ||||||
| import com.minew.beaconplus.sdk.MTPeripheral; | import com.minew.beaconplus.sdk.MTPeripheral; | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.example.beacondemo; | package com.example.beacondemo.Activity; | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AppCompatActivity; | import androidx.appcompat.app.AppCompatActivity; | ||||||
| import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||||
| @ -19,11 +19,31 @@ import android.util.Log; | |||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
|  | import com.example.beacondemo.BindView; | ||||||
|  | import com.example.beacondemo.R; | ||||||
|  | import com.example.beacondemo.adapter.RecycleAdapter; | ||||||
|  | import com.example.beacondemo.adapter.RecycleViewDivider; | ||||||
| import com.minew.beaconplus.sdk.MTCentralManager; | import com.minew.beaconplus.sdk.MTCentralManager; | ||||||
|  | import com.minew.beaconplus.sdk.MTFrameHandler; | ||||||
| import com.minew.beaconplus.sdk.MTPeripheral; | import com.minew.beaconplus.sdk.MTPeripheral; | ||||||
| import com.minew.beaconplus.sdk.enums.BluetoothState; | import com.minew.beaconplus.sdk.enums.BluetoothState; | ||||||
| import com.minew.beaconplus.sdk.enums.ConnectionStatus; | import com.minew.beaconplus.sdk.enums.ConnectionStatus; | ||||||
|  | import com.minew.beaconplus.sdk.enums.FrameType; | ||||||
| import com.minew.beaconplus.sdk.exception.MTException; | import com.minew.beaconplus.sdk.exception.MTException; | ||||||
|  | import com.minew.beaconplus.sdk.frames.AccFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.ForceFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.HTFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.IBeaconFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.InfoFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.LightFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.MinewFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.PIRFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.TamperProofFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.TemperatureFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.TlmFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.TvocFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.UidFrame; | ||||||
|  | import com.minew.beaconplus.sdk.frames.UrlFrame; | ||||||
| import com.minew.beaconplus.sdk.interfaces.ConnectionStatueListener; | import com.minew.beaconplus.sdk.interfaces.ConnectionStatueListener; | ||||||
| import com.minew.beaconplus.sdk.interfaces.GetPasswordListener; | import com.minew.beaconplus.sdk.interfaces.GetPasswordListener; | ||||||
| import com.minew.beaconplus.sdk.interfaces.MTCentralManagerListener; | import com.minew.beaconplus.sdk.interfaces.MTCentralManagerListener; | ||||||
| @ -49,6 +69,8 @@ public class MainActivity extends AppCompatActivity { | |||||||
|     public static MTPeripheral mtPeripheral; |     public static MTPeripheral mtPeripheral; | ||||||
|     private static final int REQUEST_FINE_LOCATION = 125; |     private static final int REQUEST_FINE_LOCATION = 125; | ||||||
| 
 | 
 | ||||||
|  |     ArrayList<MinewFrame> advFrames; | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     protected void onCreate(Bundle savedInstanceState) { |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
| @ -63,6 +85,11 @@ public class MainActivity extends AppCompatActivity { | |||||||
|         initManager(); |         initManager(); | ||||||
|         getRequiredPermissions(); |         getRequiredPermissions(); | ||||||
|         initListener(); |         initListener(); | ||||||
|  |         scanDevice(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void scanDevice(){ | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private boolean ensureBleExists() { |     private boolean ensureBleExists() { | ||||||
| @ -100,6 +127,87 @@ public class MainActivity extends AppCompatActivity { | |||||||
|     private void initData() { |     private void initData() { | ||||||
|         //三星手机系统可能会限制息屏下扫描,导致息屏后无法获取到广播数据 |         //三星手机系统可能会限制息屏下扫描,导致息屏后无法获取到广播数据 | ||||||
|         mMtCentralManager.startScan(); |         mMtCentralManager.startScan(); | ||||||
|  |         mMtCentralManager.setMTCentralManagerListener(new MTCentralManagerListener() { | ||||||
|  |             @Override | ||||||
|  |             public void onScanedPeripheral(final List<MTPeripheral> peripherals) { | ||||||
|  |                 for (MTPeripheral mtPeripheral : peripherals) { | ||||||
|  |                     // get FrameHandler of a device. | ||||||
|  |                     MTFrameHandler mtFrameHandler = mtPeripheral.mMTFrameHandler; | ||||||
|  |                     String mac = mtFrameHandler.getMac(); 		//mac address of device | ||||||
|  |                     String name = mtFrameHandler.getName();		// name of device | ||||||
|  |                     int battery = mtFrameHandler.getBattery();	//battery | ||||||
|  |                     int rssi = mtFrameHandler.getRssi();		//rssi | ||||||
|  |                     // all data frames of device(such as:iBeacon,UID,URL...) | ||||||
|  |                     advFrames = mtFrameHandler.getAdvFrames(); | ||||||
|  |                     /*for (MinewFrame minewFrame : advFrames) { | ||||||
|  |                         FrameType frameType = minewFrame.getFrameType(); | ||||||
|  |                         switch (frameType) { | ||||||
|  |                             case FrameiBeacon://iBeacon | ||||||
|  |                                 IBeaconFrame iBeaconFrame = (IBeaconFrame) minewFrame; | ||||||
|  |                                 Log.v("beaconplus", iBeaconFrame.getUuid() + iBeaconFrame.getMajor() + iBeaconFrame.getMinor()); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameUID://uid | ||||||
|  |                                 UidFrame uidFrame = (UidFrame) minewFrame; | ||||||
|  |                                 Log.v("beaconplus", uidFrame.getNamespaceId() + uidFrame.getInstanceId()); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameAccSensor: | ||||||
|  |                                 AccFrame accFrame = (AccFrame) minewFrame;//acc | ||||||
|  |                                 Log.v("beaconplus", String.valueOf(accFrame.getXAxis() + accFrame.getYAxis() + accFrame.getZAxis())); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameHTSensor: | ||||||
|  |                                 HTFrame htFrame = (HTFrame) minewFrame;//ht | ||||||
|  |                                 Log.v("beaconplus", String.valueOf(htFrame.getTemperature() + htFrame.getHumidity())); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameTLM: | ||||||
|  |                                 TlmFrame tlmFrame = (TlmFrame) minewFrame;//tlm | ||||||
|  |                                 Log.v("beaconplus", String.valueOf(tlmFrame.getTemperature() + tlmFrame.getBatteryVol() + tlmFrame.getSecCount() + tlmFrame.getAdvCount())); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameURL: | ||||||
|  |                                 UrlFrame urlFrame = (UrlFrame) minewFrame;//url | ||||||
|  |                                 Log.v("beaconplus", "Link:" + urlFrame.getUrlString() + "Rssi @ 0m:" + urlFrame.getTxPower()); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameLightSensor: | ||||||
|  |                                 LightFrame lightFrame = (LightFrame) minewFrame;//light | ||||||
|  |                                 Log.v("beaconplus", "battery:" + lightFrame.getBattery() + "%" + lightFrame.getLuxValue()); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameForceSensor: | ||||||
|  |                                 ForceFrame forceFrame = ((ForceFrame) minewFrame);//force | ||||||
|  |                                 Log.v("beaconplus", "battery:" + forceFrame.getBattery() + "%" + "force:" +  forceFrame.getForce() + "gram"); | ||||||
|  |                                 break; | ||||||
|  |                             case FramePIRSensor: | ||||||
|  |                                 PIRFrame pirFrame = ((PIRFrame) minewFrame);//pir | ||||||
|  |                                 Log.v("beaconplus", "battery:" + pirFrame.getBattery() + "%" + "PIR:", pirFrame.getValue()); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameTempSensor://temp | ||||||
|  |                                 TemperatureFrame temperatureFrame = (TemperatureFrame) minewFrame; | ||||||
|  |                                 Log.v("beaconplus", "battery:" + temperatureFrame.getBattery() + "%,temperature:" + String.format("%.2f", temperatureFrame.getValue()) + "°C"); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameTVOCSensor://tvoc | ||||||
|  |                                 TvocFrame tvocFrame = (TvocFrame) minewFrame; | ||||||
|  |                                 Log.v("beaconplus", "battery:" + tvocFrame.getBattery() + ",TVOC:"+ tvocFrame.getValue() + "ppb," + "battery:" +tvocFrame.getBattery() + "mV"); | ||||||
|  |                                 break; | ||||||
|  |                             case FrameLineBeacon://FrameLineBeacon | ||||||
|  |                                 FrameLineBeacon lineBeacon = ((FrameLineBeacon) minewFrame); | ||||||
|  |                                 Log.v("beaconplus", "Hwid:" + lineBeacon.getHwid() | ||||||
|  |                                         + ",Rssi@1m:", lineBeacon.getTxPower() | ||||||
|  |                                         + ",authentication:"lineBeacon.getAuthentication() | ||||||
|  |                                         + ",timesTamp:" + lineBeacon.getTimesTamp()); | ||||||
|  |                                 break; | ||||||
|  |                             case TamperProofFrame://TamperProofFrame | ||||||
|  |                                 TamperProofFrame tamperProofFrame = ((TamperProofFrame) minewFrame);// | ||||||
|  |                                 Log.v("beaconplus", "battery:" + tamperProofFrame.getBattery()); | ||||||
|  |                                 break; | ||||||
|  |                             case InfoFrame://InfoFrame | ||||||
|  |                                 InfoFrame infoFrame = ((InfoFrame) minewFrame);// | ||||||
|  |                                 Log.v("beaconplus", infoFrame.getMajor() + infoFrame.getMinor() + 	infoFrame.getBatteryVoltage()); | ||||||
|  |                                 break; | ||||||
|  |                             default: | ||||||
|  |                                 break; | ||||||
|  |                         } | ||||||
|  |                     }*/ | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void initView() { |     private void initView() { | ||||||
| @ -107,8 +215,8 @@ public class MainActivity extends AppCompatActivity { | |||||||
|         mRecycle.setLayoutManager(layoutManager); |         mRecycle.setLayoutManager(layoutManager); | ||||||
|         mAdapter = new RecycleAdapter(); |         mAdapter = new RecycleAdapter(); | ||||||
|         mRecycle.setAdapter(mAdapter); |         mRecycle.setAdapter(mAdapter); | ||||||
|         mRecycle.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager |         /*mRecycle.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager | ||||||
|                 .HORIZONTAL)); |                 .HORIZONTAL));*/ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void initManager() { |     private void initManager() { | ||||||
| @ -122,6 +230,7 @@ public class MainActivity extends AppCompatActivity { | |||||||
|                 break; |                 break; | ||||||
|             case BluetoothStatePowerOff: |             case BluetoothStatePowerOff: | ||||||
|                 Log.e("tag", "BluetoothStatePowerOff"); |                 Log.e("tag", "BluetoothStatePowerOff"); | ||||||
|  | 
 | ||||||
|                 break; |                 break; | ||||||
|             case BluetoothStatePowerOn: |             case BluetoothStatePowerOn: | ||||||
|                 Log.e("tag", "BluetoothStatePowerOn"); |                 Log.e("tag", "BluetoothStatePowerOn"); | ||||||
| @ -137,6 +246,7 @@ public class MainActivity extends AppCompatActivity { | |||||||
|                         break; |                         break; | ||||||
|                     case BluetoothStatePowerOff: |                     case BluetoothStatePowerOff: | ||||||
|                         Log.e("tag", "BluetoothStatePowerOff"); |                         Log.e("tag", "BluetoothStatePowerOff"); | ||||||
|  |                         showBLEDialog(); | ||||||
|                         break; |                         break; | ||||||
|                     case BluetoothStatePowerOn: |                     case BluetoothStatePowerOn: | ||||||
|                         Log.e("tag", "BluetoothStatePowerOn"); |                         Log.e("tag", "BluetoothStatePowerOn"); | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.example.beacondemo; | package com.example.beacondemo.adapter; | ||||||
| 
 | 
 | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| @ -6,6 +6,7 @@ import android.widget.TextView; | |||||||
| 
 | 
 | ||||||
| import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||||
| 
 | 
 | ||||||
|  | import com.example.beacondemo.R; | ||||||
| import com.minew.beaconplus.sdk.MTPeripheral; | import com.minew.beaconplus.sdk.MTPeripheral; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.example.beacondemo; | package com.example.beacondemo.adapter; | ||||||
| 
 | 
 | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.res.TypedArray; | import android.content.res.TypedArray; | ||||||
| @ -6,7 +6,7 @@ | |||||||
|     android:layout_width="match_parent" |     android:layout_width="match_parent" | ||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|     android:orientation="vertical" |     android:orientation="vertical" | ||||||
|     tools:context=".DetailActivity"> |     tools:context=".Activity.DetailActivity"> | ||||||
| 
 | 
 | ||||||
|     <RelativeLayout |     <RelativeLayout | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|  | |||||||
| @ -5,12 +5,14 @@ | |||||||
|     xmlns:tools="http://schemas.android.com/tools" |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|     android:layout_width="match_parent" |     android:layout_width="match_parent" | ||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|     tools:context=".MainActivity"> |     tools:context=".Activity.MainActivity" | ||||||
|  |     > | ||||||
| 
 | 
 | ||||||
|     <androidx.recyclerview.widget.RecyclerView |     <androidx.recyclerview.widget.RecyclerView | ||||||
|         android:id="@+id/recycle" |         android:id="@+id/recycle" | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="match_parent"> |         android:layout_height="match_parent" | ||||||
|  |         > | ||||||
| 
 | 
 | ||||||
|     </androidx.recyclerview.widget.RecyclerView> |     </androidx.recyclerview.widget.RecyclerView> | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user