@@ -41,6 +41,7 @@ public void onError(MSException msException) {
41
41
42
42
}
43
43
});
44
+ autoStopScan (context , 10000 );
44
45
}
45
46
46
47
@ Override
@@ -51,66 +52,67 @@ public void onFailure(MSException msException) {
51
52
} catch (MSException e ) {
52
53
e .printStackTrace ();
53
54
}
54
- if (beaconstac != null ) {
55
- Handler handler = new Handler ();
56
- handler .postDelayed (new Runnable () {
55
+ }
56
+
57
+ @ Override
58
+ public void onLost (Message message ) {
59
+ }
60
+ });
61
+ }
62
+ }
63
+
64
+ private void autoStopScan (final Context context , int duration ){
65
+ if (beaconstac != null ) {
66
+ Handler handler = new Handler ();
67
+ handler .postDelayed (new Runnable () {
68
+ @ Override
69
+ public void run () {
70
+ beaconstac .stopScanningBeacons (new MSErrorListener () {
71
+ @ Override
72
+ public void onError (MSException msException ) {
73
+
74
+ }
75
+ });
76
+ }
77
+ }, duration ); // Set the duration for which the scan needs to run for.
78
+ } else {
79
+ // Handle reinitialization if Beaconstac's instance is null.
80
+ Handler handler = new Handler ();
81
+ handler .postDelayed (new Runnable () {
82
+ @ Override
83
+ public void run () {
84
+ try {
85
+ if (ActivityCompat .checkSelfPermission (context .getApplicationContext (), Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED || ActivityCompat .checkSelfPermission (context .getApplicationContext (), Manifest .permission .ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
86
+ return ;
87
+ }
88
+ beaconstac = Beaconstac .initialize (context .getApplicationContext (), "MY_DEVELOPER_TOKEN" , new MSSyncListener () {
57
89
@ Override
58
- public void run () {
90
+ public void onSuccess () {
59
91
beaconstac .stopScanningBeacons (new MSErrorListener () {
60
92
@ Override
61
93
public void onError (MSException msException ) {
62
94
63
95
}
64
96
});
65
97
}
66
- }, 10000 ); // Set the duration for which the scan needs to run for.
67
- } else {
68
98
69
- // Handle reinitialization if Beaconstac's instance is null.
70
- Handler handler = new Handler ();
71
- handler .postDelayed (new Runnable () {
72
99
@ Override
73
- public void run () {
74
- try {
75
- if (ActivityCompat .checkSelfPermission (context .getApplicationContext (), Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED || ActivityCompat .checkSelfPermission (context .getApplicationContext (), Manifest .permission .ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
76
- return ;
77
- }
78
- beaconstac = Beaconstac .initialize (context .getApplicationContext (), "MY_DEVELOPER_TOKEN" , new MSSyncListener () {
79
- @ Override
80
- public void onSuccess () {
81
- beaconstac .stopScanningBeacons (new MSErrorListener () {
82
- @ Override
83
- public void onError (MSException msException ) {
84
-
85
- }
86
- });
87
- }
88
-
89
- @ Override
90
- public void onFailure (MSException msException ) {
91
- // Stop scan even if initialization failed
92
- beaconstac .stopScanningBeacons (new MSErrorListener () {
93
- @ Override
94
- public void onError (MSException msException ) {
100
+ public void onFailure (MSException msException ) {
101
+ // Stop scan even if initialization failed
102
+ beaconstac .stopScanningBeacons (new MSErrorListener () {
103
+ @ Override
104
+ public void onError (MSException msException ) {
95
105
96
- }
97
- });
98
- }
99
- });
100
- } catch (MSException e ) {
101
- e .printStackTrace ();
102
- }
106
+ }
107
+ });
103
108
}
104
- }, 10000 ); // Set the duration for which the scan needs to run for.
105
-
106
-
109
+ });
110
+ } catch ( MSException e ) {
111
+ e . printStackTrace ();
107
112
}
108
113
}
114
+ }, duration ); // Set the duration for which the scan needs to run for.
109
115
110
- @ Override
111
- public void onLost (Message message ) {
112
- }
113
- });
114
116
}
115
117
}
116
118
}
0 commit comments