Skip to content

Commit

Permalink
fix(downloads): foreground service type
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed Dec 29, 2024
1 parent 7931364 commit fe7e1cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROCESSING"
android:minSdkVersion="35"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
android:minSdkVersion="29"/>

<application
android:name=".App"
Expand All @@ -19,7 +23,7 @@
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/Theme.App.Starting"
tools:targetApi="34">
tools:targetApi="35">
<activity
android:name=".ui.activity.downloads.DownloadsActivity"
android:exported="false"
Expand Down Expand Up @@ -62,7 +66,6 @@
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -88,7 +91,8 @@
<service
android:name=".service.media.MediaDownloadsService"
android:enabled="true"
android:exported="false"/>
android:exported="false"
android:foregroundServiceType="mediaProcessing|mediaPlayback" />

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.app.Service
import android.app.TaskStackBuilder
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import androidx.annotation.RequiresApi
Expand Down Expand Up @@ -81,7 +82,19 @@ class MediaDownloadsService : Service() {

manager.apply {
builder.setProgress(100, 0, true)
notify(1, builder.build())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
startForeground(
1, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING
)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
1,
builder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
)
} else {
startForeground(1, builder.build())
}
}

listener = DListener(manager, builder, this)
Expand Down

0 comments on commit fe7e1cd

Please sign in to comment.