Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,23 @@ public void getRunTimePermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(LoginActivity.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(LoginActivity.this,
Manifest.permission.ACCESS_NETWORK_STATE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
Comment on lines -312 to -313
Copy link
Member

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.

Copy link
Author

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.

Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WAKE_LOCK,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.VIBRATE,

}, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package io.github.project_travel_mate.travel;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import org.osmdroid.views.MapView;

Expand Down Expand Up @@ -44,6 +51,41 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_list_real_time);
ButterKnife.bind(this);

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();
}
}

public void getLocation() {
// Get user's current location
mTracker = new GPSTracker(this);
MapView mMap = findViewById(R.id.action_map_view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Copy link
Member

@Swati4star Swati4star Nov 3, 2020

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ protected void onCreate(Bundle savedInstanceState) {

ButterKnife.bind(this);



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change? Revert this

Choose a reason for hiding this comment

The 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);
Expand Down
11 changes: 9 additions & 2 deletions Android/app/src/main/java/utils/GPSTracker.java
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;
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt we ask for permissions if they are not granted?

Copy link
Author

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -156,4 +162,5 @@ public void displayLocationRequest(Context context, MapView mapView) {
mLocationOverlay.enableMyLocation();
mapView.getOverlays().add(mLocationOverlay);
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

1 change: 0 additions & 1 deletion Android/app/src/main/res/layout/hotel_listitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

app:srcCompat="@color/colorAccent" />

<TextView
Expand Down