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

Notification runtime permission #315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions app/src/main/java/com/fmsys/snapdrop/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
}
});

private final ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), result -> {});

Check notice on line 149 in app/src/main/java/com/fmsys/snapdrop/MainActivity.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/fmsys/snapdrop/MainActivity.java#L149

'{' is not followed by whitespace.

@RequiresApi(api = Build.VERSION_CODES.M)
@SuppressLint({"SetJavaScriptEnabled", "ClickableViewAccessibility", "RestrictedApi"})
Expand Down Expand Up @@ -261,6 +262,16 @@
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
Snackbar.make(binding.getRoot(), R.string.grant_notification_permission, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.ok, view -> permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS))
.show();
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
}
}

binding.pullToRefresh.setOnRefreshListener(() -> {
binding.noConnectionScreen.setVisibility(View.GONE);
refreshWebsite(true);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<string name="reset">reset</string>
<string name="copy">copy</string>
<string name="retry">retry</string>
<string name="ok">OK</string>

<!-- Settings / About -->
<string name="home_as_up_indicator_about">About</string>
Expand Down Expand Up @@ -64,6 +65,9 @@
<string name="retain_location_metadata_summary_off">Some media files might contain location data that are stripped by default. Grant permission to include full metadata</string>
<string name="retain_location_metadata_summary_on">The app has full file access currently</string>

<!-- Permissions -->
<string name="grant_notification_permission">Please grant the notification permission to receive updates on file transfers</string>

<string name="settings_theme_title">Theme</string>
<string-array name="darkmode_entries">
<item>System Default</item>
Expand Down
Loading