-
-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#739-Implemented runtime permissions #825
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,14 @@ | |
import android.content.SharedPreferences; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.preference.PreferenceManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
|
@@ -23,6 +26,7 @@ | |
import android.widget.LinearLayout; | ||
import android.widget.ScrollView; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.afollestad.materialdialogs.MaterialDialog; | ||
import com.airbnb.lottie.LottieAnimationView; | ||
|
@@ -100,6 +104,41 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
||
setTitle("Map View"); | ||
|
||
getRunTimePermission(); | ||
} | ||
|
||
private void getRunTimePermission() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED && | ||
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED) { | ||
getLocation(); | ||
} else { | ||
ActivityCompat.requestPermissions(this, | ||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, | ||
Manifest.permission.ACCESS_COARSE_LOCATION}, 100); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | ||
@NonNull int[] grantResults) { | ||
if (requestCode != 100) { | ||
return; | ||
} | ||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED | ||
&& ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED) { | ||
getLocation(); | ||
} else { | ||
Toast.makeText(this, "Permissions Denied", Toast.LENGTH_SHORT).show(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have been using snackbar everywhere, and please dont use constant strings. Add them to strings.xml There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
} | ||
|
||
private void getLocation() { | ||
// Get user's current location | ||
tracker = new GPSTracker(this); | ||
if (!tracker.canGetLocation()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
||
ButterKnife.bind(this); | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? Revert this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mam can u pls help me?...m getting <! DOCTYPE html> error during login time ....how can I solve this error |
||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
createCode(); | ||
scan.setOnClickListener(this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package utils; | ||
|
||
import android.Manifest; | ||
import android.app.Service; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.location.Location; | ||
import android.location.LocationListener; | ||
import android.location.LocationManager; | ||
import android.os.Bundle; | ||
import android.os.IBinder; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.util.Log; | ||
|
||
import org.osmdroid.views.MapView; | ||
|
@@ -56,7 +59,10 @@ private Location getLocation() { | |
|
||
if (!isGPSEnabled && !isNetworkEnabled) { | ||
// no network provider is enabled | ||
} else { | ||
} else if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) | ||
== PackageManager.PERMISSION_GRANTED) { | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldnt we ask for permissions if they are not granted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are asking for permissions where this service is called, without giving the permission user can not proceed. In this service we are just checking if the permission is given(we can not call locationManager.requestLocationUpdates without checking if permissions are given or not). |
||
this.mCanGetLocation = true; | ||
// First get mLocation from Network Provider | ||
if (isNetworkEnabled) { | ||
|
@@ -156,4 +162,5 @@ public void displayLocationRequest(Context context, MapView mapView) { | |
mLocationOverlay.enableMyLocation(); | ||
mapView.getOverlays().add(mLocationOverlay); | ||
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
android:layout_width="match_parent" | ||
android:layout_height="70dp" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentTop="true" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
app:srcCompat="@color/colorAccent" /> | ||
|
||
<TextView | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why have you removed these? We need these permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can u please tell me where u r accessing contact?, Actually i am not able to login as of now in the App becuase of #824.