This repository was archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CAPAC-8 #352
Open
Open
CAPAC-8 #352
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 6 additions & 8 deletions
app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="pub.devrel.easypermissions.sample"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.READ_CONTACTS" /> | ||
|
||
<uses-permission android:name="android.permission.READ_SMS" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:label="@string/app_name" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="AllowBackup,GoogleAppIndexingWarning"> | ||
|
||
<activity | ||
android:name=".ContactsActivity" | ||
android:exported="false" /> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> | ||
</manifest> |
114 changes: 114 additions & 0 deletions
app/src/main/java/pub/devrel/easypermissions/sample/ContactsActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package pub.devrel.easypermissions.sample; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.Manifest; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import java.util.List; | ||
|
||
import pub.devrel.easypermissions.AfterPermissionGranted; | ||
import pub.devrel.easypermissions.AppSettingsDialog; | ||
import pub.devrel.easypermissions.EasyPermissions; | ||
|
||
public class ContactsActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, | ||
EasyPermissions.RationaleCallbacks { | ||
|
||
private static final int RC_CONTACTS_PERM = 126; | ||
TextView message; | ||
private static final String TAG = "ContactsActivity"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_contacts); | ||
message = findViewById(R.id.textPermission); | ||
contactsTask(); | ||
contactsMessage(); | ||
} | ||
|
||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
contactsMessage(); | ||
|
||
|
||
} | ||
|
||
public void contactsMessage(){ | ||
if(hasContactsPermission()){ | ||
message.setText(getString(R.string.permission_accepted)); | ||
}else{ | ||
message.setText(getString(R.string.permission_denied)); | ||
} | ||
} | ||
|
||
|
||
private boolean hasContactsPermission() { | ||
return EasyPermissions.hasPermissions(this, Manifest.permission.READ_CONTACTS); | ||
} | ||
|
||
@AfterPermissionGranted(RC_CONTACTS_PERM) | ||
public void contactsTask() { | ||
if (hasContactsPermission()) { | ||
// Have permissions, do the thing! | ||
Toast.makeText(this, "TODO: Contacts things", Toast.LENGTH_LONG).show(); | ||
} else { | ||
// Ask for both permissions | ||
EasyPermissions.requestPermissions( | ||
this, | ||
getString(R.string.rationale_contacts), | ||
RC_CONTACTS_PERM, | ||
Manifest.permission.READ_CONTACTS); | ||
} | ||
} | ||
|
||
/*@Override | ||
public void onRequestPermissionsResult(int requestCode, | ||
@NonNull String[] permissions, | ||
@NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
// EasyPermissions handles the request result. | ||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); | ||
}*/ | ||
|
||
@Override | ||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) { | ||
Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size()); | ||
/* if(requestCode == RC_CONTACTS_PERM){ | ||
contactsMessage(); | ||
}*/ | ||
} | ||
|
||
@Override | ||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) { | ||
Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size()); | ||
|
||
// (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN." | ||
// This will display a dialog directing them to enable the permission in app settings. | ||
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { | ||
new AppSettingsDialog.Builder(this).build().show(); | ||
} | ||
|
||
/*if(requestCode == RC_CONTACTS_PERM){ | ||
contactsMessage(getString(R.string.permission_denied)); | ||
}*/ | ||
} | ||
|
||
|
||
@Override | ||
public void onRationaleAccepted(int requestCode) { | ||
Log.d(TAG, "onRationaleAccepted:" + requestCode); | ||
} | ||
|
||
@Override | ||
public void onRationaleDenied(int requestCode) { | ||
Log.d(TAG, "onRationaleDenied:" + requestCode); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
app/src/main/res/layout/activity_contacts.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context=".ContactsActivity"> | ||
|
||
<TextView | ||
android:id="@+id/textPermission" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="" | ||
android:textSize="24dp" | ||
android:textAlignment="center" | ||
android:textColor="@color/colorPrimary" | ||
android:gravity="center_horizontal" /> | ||
</LinearLayout> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.