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

View File

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

View File

@ -1,12 +1,15 @@
package org.pixeldroid.app.utils.notificationsWorker package org.pixeldroid.app.utils.notificationsWorker
import android.Manifest
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationChannelGroup import android.app.NotificationChannelGroup
import android.app.NotificationManager import android.app.NotificationManager
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
@ -143,7 +146,10 @@ class NotificationsWorker(
) )
with(NotificationManagerCompat.from(applicationContext)) { 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)) { with(NotificationManagerCompat.from(applicationContext)) {
// notificationId is a unique int for each notification // 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())
} }
} }