Update permissions

This commit is contained in:
Matthieu 2022-11-03 15:16:27 +01:00
parent c6d43797cc
commit d78ef56489
3 changed files with 32 additions and 13 deletions

View File

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
@ -20,13 +21,11 @@
<application
android:name=".utils.PixelDroidApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">
android:theme="@style/AppTheme">
<activity
android:name=".posts.AlbumActivity"
android:exported="false"
@ -135,12 +134,6 @@
android:scheme="@string/auth_scheme" />
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:exported="true"
android:screenOrientation="sensorPortrait"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".searchDiscover.SearchActivity"
android:exported="true"

View File

@ -1,15 +1,21 @@
package org.pixeldroid.app
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.GravityCompat
@ -121,11 +127,22 @@ class MainActivity : BaseThemedWithoutBarActivity() {
if(showNotification){
binding.viewPager.currentItem = 3
}
enablePullNotifications(this)
if (ActivityCompat.checkSelfPermission(applicationContext,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) enablePullNotifications(this)
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
}
private val notificationPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) enablePullNotifications(this)
}
// Checks if the activity was launched from a notification from another account than the
// current active one, and if so switches to that account
private fun notificationFromOtherUser(): Boolean {

View File

@ -1,12 +1,15 @@
package org.pixeldroid.app.utils.notificationsWorker
import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.work.CoroutineWorker
@ -143,7 +146,10 @@ class NotificationsWorker(
)
with(NotificationManagerCompat.from(applicationContext)) {
notify(uniqueUserId.hashCode(), groupBuilder.build())
if (ActivityCompat.checkSelfPermission(applicationContext,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) notify(uniqueUserId.hashCode(), groupBuilder.build())
}
}
@ -216,7 +222,10 @@ class NotificationsWorker(
with(NotificationManagerCompat.from(applicationContext)) {
// notificationId is a unique int for each notification
notify((uniqueUserId + notification.id).hashCode(), builder.build())
if (ActivityCompat.checkSelfPermission(applicationContext,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) notify((uniqueUserId + notification.id).hashCode(), builder.build())
}
}