mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3330 permissions
This commit is contained in:
parent
74ce176540
commit
9bd05e1e8d
3 changed files with 38 additions and 0 deletions
|
@ -152,6 +152,10 @@
|
|||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="@string/default_notification_channel_id" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -8,8 +8,10 @@ import android.graphics.Color
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.FragmentContainerView
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
@ -101,6 +103,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
askNotificationPermission()
|
||||
setupWindowInsets()
|
||||
inject()
|
||||
setupTheme()
|
||||
|
@ -640,6 +643,36 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
|
|||
componentManager().mainEntryComponent.release()
|
||||
}
|
||||
|
||||
// Declare the launcher at the top of your Activity/Fragment:
|
||||
private val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission(),
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
// FCM SDK (and your app) can post notifications.
|
||||
} else {
|
||||
// TODO: Inform user that that your app will not show notifications.
|
||||
}
|
||||
}
|
||||
|
||||
private fun askNotificationPermission() {
|
||||
// This is only necessary for API level >= 33 (TIRAMISU)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) ==
|
||||
PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
// FCM SDK (and your app) can post notifications.
|
||||
} else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
|
||||
// TODO: display an educational UI explaining to the user the features that will be enabled
|
||||
// by them granting the POST_NOTIFICATION permission. This UI should provide the user
|
||||
// "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
|
||||
// If the user selects "No thanks," allow the user to continue without notifications.
|
||||
} else {
|
||||
// Directly ask for the permission
|
||||
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val AUTO_UPDATE_URL = "https://fra1.digitaloceanspaces.com/anytype-release/latest-android.json"
|
||||
const val SHARE_DIALOG_LABEL = "anytype.dialog.share.label"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<string name="amplitude_api_key" translatable="false">1ba981d1a9afb8af8c81847ef3383a20</string>
|
||||
<string name="amplitude_api_key_debug" translatable="false">b9791dd64a1e9f07a330a4ac9feb1f10</string>
|
||||
<string name="default_notification_channel_id" translatable="false">fcm_default_channel</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue