Skip to content

Commit

Permalink
resolve location issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdubey021 committed Oct 1, 2018
1 parent 548c42d commit 3348bba
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 285 deletions.
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'

testCompile 'junit:junit:4.12'
compile project(':gpslibrary')
}
46 changes: 20 additions & 26 deletions app/src/main/java/org/ankit/gpstracker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,43 @@

import android.Manifest;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.mock.MockPackageManager;

import org.ankit.gpslibrary.ADLocation;
import org.ankit.gpslibrary.MyTracker;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements MyTracker.ADLocationListener {
private static final int REQUEST_CODE_PERMISSION = 2;
String mPermission = Manifest.permission.ACCESS_FINE_LOCATION;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
if (ActivityCompat.checkSelfPermission(this, mPermission)
!= MockPackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, new String[]{mPermission, Manifest.permission.READ_PHONE_STATE},
REQUEST_CODE_PERMISSION);
}else{
MyTracker tracker=new MyTracker(this);
System.out.println(tracker.address);
}
} catch (Exception e) {
e.printStackTrace();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//ask for permission
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 101);
}
else{
findLoc();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_PERMISSION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
MyTracker tracker=new MyTracker(this);
System.out.println(tracker.address);

} else {

System.out.println("permission denied!");
private void findLoc(){
new MyTracker(getApplicationContext(),this).track();
}

}
break;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
findLoc();
}
}
@Override
public void whereIAM(ADLocation loc) {
System.out.println(loc);
}
}
1 change: 1 addition & 0 deletions gpslibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.google.android.gms:play-services:11.0.4'
testCompile 'junit:junit:4.12'
}
1 change: 1 addition & 0 deletions gpslibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.ankit.gpslibrary">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

Expand Down
24 changes: 24 additions & 0 deletions gpslibrary/src/main/java/org/ankit/gpslibrary/ADLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.ankit.gpslibrary;

public class ADLocation {
public double lat;
public double longi;
public String address;
public String city;
public String state;
public String country;
public String pincode;

@Override
public String toString() {
return "ADLocation{" +
"lat=" + lat +
", longt=" + longi +
", address='" + address + '\'' +
", city='" + city + '\'' +
", state='" + state + '\'' +
", country='" + country + '\'' +
", pincode='" + pincode + '\'' +
'}';
}
}
106 changes: 0 additions & 106 deletions gpslibrary/src/main/java/org/ankit/gpslibrary/IPTracker.java

This file was deleted.

Loading

0 comments on commit 3348bba

Please sign in to comment.