Skip to content

Commit

Permalink
add the draw permission handling for AA
Browse files Browse the repository at this point in the history
  • Loading branch information
sstimac committed Oct 23, 2024
1 parent 7f13bfe commit 7523c4e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.doublesymmetry.trackplayer.module

import android.content.*
import android.media.MediaDescription
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.net.Uri
import android.support.v4.media.RatingCompat
import android.provider.Settings
import android.support.v4.media.MediaBrowserCompat.MediaItem
import android.support.v4.media.MediaDescriptionCompat
import android.support.v4.media.RatingCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.media.utils.MediaConstants
import com.doublesymmetry.kotlinaudio.models.Capability
Expand Down Expand Up @@ -732,4 +732,31 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
)
callback.resolve(null)
}

@ReactMethod
fun turnOffShowWhenLocked(callback: Promise) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
val activity = reactApplicationContext.currentActivity
activity!!.setShowWhenLocked(false)
activity!!.setTurnScreenOn(false)
}

callback.resolve(null)
}

@ReactMethod
fun getDrawOverAppsPermission(callback: Promise) {
val activity = reactApplicationContext.currentActivity
callback.resolve(Settings.canDrawOverlays(activity))
}

@ReactMethod
fun askDrawOverAppsPermission(callback: Promise) {
val context = reactApplicationContext
val packageName = context.packageName
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
callback.resolve(null)
}
}
12 changes: 12 additions & 0 deletions src/trackPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,15 @@ export function setBrowseTreeStyle(
TrackPlayer.setBrowseTreeStyle(browsableStyle, playableStyle);
return null;
}

export function turnOffShowWhenLocked() {
return TrackPlayer.turnOffShowWhenLocked();
}

export function getDrawOverAppsPermission() {
return TrackPlayer.getDrawOverAppsPermission();
}

export function askDrawOverAppsPermission() {
return TrackPlayer.askDrawOverAppsPermission();
}

0 comments on commit 7523c4e

Please sign in to comment.