Skip to content

Commit 95cce45

Browse files
committed
Fix errors and set min sdk version up to 23
1 parent 170806e commit 95cce45

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
buildToolsVersion "22.0.1"
1212
defaultConfig {
1313
applicationId "com.firemaples.androidlocationremotecontrol"
14-
minSdkVersion 14
14+
minSdkVersion 23
1515
targetSdkVersion 24
1616
versionCode 1
1717
versionName "1.0"
@@ -33,9 +33,10 @@ dependencies {
3333
compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
3434
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.1.3'
3535
compile 'com.android.support:appcompat-v7:24.2.1'
36-
compile 'com.google.android.gms:play-services:9.4.0'
36+
compile 'com.google.android.gms:play-services-location:9.4.0'
37+
compile 'com.google.android.gms:play-services-maps:9.4.0'
3738
compile 'org.apache.commons:commons-lang3:3.4'
38-
compile files('libs/Java-WebSocket-Library-1.2.1-SNAPSHOT.jar')
39-
39+
// compile files('libs/Java-WebSocket-Library-1.2.1-SNAPSHOT.jar')
40+
compile 'org.java-websocket:Java-WebSocket:1.3.0'
4041
}
4142

app/src/main/java/com/firemaples/androidlocationremotecontrol/MainActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ public void run() {
179179
});
180180
}
181181

182+
@Override
183+
public void onMockModeStartingFailed(String message) {
184+
AlertDialog.Builder ab = new AlertDialog.Builder(MainActivity.this);
185+
ab.setTitle("Error");
186+
ab.setMessage(message);
187+
ab.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
188+
@Override
189+
public void onClick(DialogInterface dialogInterface, int i) {
190+
finish();
191+
}
192+
});
193+
ab.setCancelable(false);
194+
ab.show();
195+
}
196+
182197
private void showWaitingString(RemoteListenerService service) {
183198
new ShowConnectionInfoThread(service).start();
184199
}

app/src/main/java/com/firemaples/androidlocationremotecontrol/RemoteListenerService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import android.os.SystemClock;
1515
import android.support.v4.app.ActivityCompat;
1616
import android.support.v4.app.NotificationCompat;
17-
import android.widget.Toast;
1817

1918
import com.google.android.gms.common.ConnectionResult;
2019
import com.google.android.gms.common.api.GoogleApiClient;
@@ -87,7 +86,7 @@ public void stopListening() {
8786
if (socketServer != null) {
8887
try {
8988
socketServer.stop(1);
90-
} catch (InterruptedException e) {
89+
} catch (Exception e) {
9190
e.printStackTrace();
9291
}
9392
}
@@ -141,18 +140,18 @@ private void mockLocation(double lat, double lng) {
141140

142141
private void disableMockProvider() {
143142
if (locationManager != null) {
144-
locationManager.setTestProviderEnabled(locationProvider, false);
145143
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
146144
return;
147145
}
148146
try {
147+
locationManager.setTestProviderEnabled(locationProvider, false);
149148
LocationServices.FusedLocationApi.setMockMode(googleApiClient, false);
149+
locationManager.clearTestProviderEnabled(locationProvider);
150+
locationManager.clearTestProviderStatus(locationProvider);
151+
locationManager.clearTestProviderLocation(locationProvider);
150152
} catch (Exception e) {
151153
e.printStackTrace();
152154
}
153-
locationManager.clearTestProviderEnabled(locationProvider);
154-
locationManager.clearTestProviderStatus(locationProvider);
155-
locationManager.clearTestProviderLocation(locationProvider);
156155
}
157156

158157
removeNotification();
@@ -281,10 +280,9 @@ protected void startMockMode() {
281280
try {
282281
//noinspection MissingPermission
283282
LocationServices.FusedLocationApi.setMockMode(googleApiClient, true);
284-
} catch (Exception e) {
283+
} catch (SecurityException e) {
285284
e.printStackTrace();
286-
Toast.makeText(this, "Please set this app in mock location app", Toast.LENGTH_LONG).show();
287-
stopSelf();
285+
callback.onMockModeStartingFailed(e.getMessage());
288286
}
289287
}
290288

@@ -312,5 +310,7 @@ public interface OnRemoteListenerCallback {
312310
void onDisconnected(RemoteListenerService service);
313311

314312
void onMockLocationChange(RemoteListenerService service, double lat, double lng);
313+
314+
void onMockModeStartingFailed(String message);
315315
}
316316
}

gradle/wrapper/gradle-wrapper.jar

52.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Wed Sep 21 14:22:21 CST 2016
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 commit comments

Comments
 (0)