make build working with target sdk 31

This commit is contained in:
Holger Müller 2022-04-08 22:57:23 +02:00
parent 1c7c4839b3
commit 5890c32b7e
5 changed files with 42 additions and 21 deletions

View File

@ -1,5 +1,5 @@
ext.versions = [
minSdk : 21,
targetSdk : 30,
targetSdk : 31,
compileSdk : 31,
]

View File

@ -40,7 +40,8 @@
<activity android:name=".activity.NavigationActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH"/>
@ -63,7 +64,7 @@
<service android:name=".playback.PlaybackService"
android:label="@string/common.appname"
android:exported="true">
android:exported="false">
<intent-filter>
<action android:name="androidx.media3.session.MediaLibraryService" />
@ -71,7 +72,8 @@
</intent-filter>
</service>
<receiver android:name=".receiver.UltrasonicIntentReceiver">
<receiver android:name=".receiver.UltrasonicIntentReceiver"
android:exported="false">
<intent-filter>
<action android:name="org.moire.ultrasonic.CMD_TOGGLEPAUSE"/>
<action android:name="org.moire.ultrasonic.CMD_PLAY"/>
@ -85,7 +87,8 @@
</receiver>
<receiver
android:name=".provider.UltrasonicAppWidgetProvider4X1"
android:label="Ultrasonic (4x1)">
android:label="Ultrasonic (4x1)"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
@ -96,7 +99,8 @@
</receiver>
<receiver
android:name=".provider.UltrasonicAppWidgetProvider4X2"
android:label="Ultrasonic (4x2)">
android:label="Ultrasonic (4x2)"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
@ -107,7 +111,8 @@
</receiver>
<receiver
android:name=".provider.UltrasonicAppWidgetProvider4X3"
android:label="Ultrasonic (4x3)">
android:label="Ultrasonic (4x3)"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
@ -118,7 +123,8 @@
</receiver>
<receiver
android:name=".provider.UltrasonicAppWidgetProvider4X4"
android:label="Ultrasonic (4x4)">
android:label="Ultrasonic (4x4)"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
@ -127,14 +133,16 @@
android:name="android.appwidget.provider"
android:resource="@xml/appwidget_info_4x4"/>
</receiver>
<receiver android:name=".receiver.MediaButtonIntentReceiver">
<receiver android:name=".receiver.MediaButtonIntentReceiver"
android:exported="false">
<intent-filter android:priority="2147483647">
<action android:name="android.intent.action.MEDIA_BUTTON"/>
</intent-filter>
</receiver>
<provider
android:name=".provider.SearchSuggestionProvider"
android:authorities="org.moire.ultrasonic.provider.SearchSuggestionProvider"/>
android:authorities="org.moire.ultrasonic.provider.SearchSuggestionProvider"
android:exported="false" />
</application>

View File

@ -15,7 +15,6 @@
*/
package org.moire.ultrasonic.playback
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Intent
import androidx.media3.common.AudioAttributes
@ -135,11 +134,14 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
.build()
}
@SuppressLint("UnspecifiedImmutableFlag")
private fun getPendingIntentForContent(): PendingIntent {
val intent = Intent(this, NavigationActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
val flags = PendingIntent.FLAG_UPDATE_CURRENT
var flags = PendingIntent.FLAG_UPDATE_CURRENT
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// needed starting Android 12 (S = 31)
flags = flags or PendingIntent.FLAG_IMMUTABLE
}
intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
return PendingIntent.getActivity(this, 0, intent, flags)
}

View File

@ -7,7 +7,6 @@
package org.moire.ultrasonic.provider
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
@ -164,7 +163,6 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
/**
* Link up various button actions using [PendingIntent].
*/
@SuppressLint("UnspecifiedImmutableFlag")
private fun linkButtons(context: Context, views: RemoteViews, playerActive: Boolean) {
var intent = Intent(
context,
@ -173,8 +171,13 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
if (playerActive) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
intent.action = "android.intent.action.MAIN"
intent.addCategory("android.intent.category.LAUNCHER")
var flags = PendingIntent.FLAG_UPDATE_CURRENT
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// needed starting Android 12 (S = 31)
flags = flags or PendingIntent.FLAG_IMMUTABLE
}
var pendingIntent =
PendingIntent.getActivity(context, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.getActivity(context, 10, intent, flags)
views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent)
views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent)
@ -185,7 +188,12 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)
)
pendingIntent = PendingIntent.getBroadcast(context, 11, intent, 0)
flags = 0
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// needed starting Android 12 (S = 31)
flags = flags or PendingIntent.FLAG_IMMUTABLE
}
pendingIntent = PendingIntent.getBroadcast(context, 11, intent, flags)
views.setOnClickPendingIntent(R.id.control_play, pendingIntent)
intent = Intent(Constants.CMD_PROCESS_KEYCODE)
intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java)
@ -193,7 +201,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)
)
pendingIntent = PendingIntent.getBroadcast(context, 12, intent, 0)
pendingIntent = PendingIntent.getBroadcast(context, 12, intent, flags)
views.setOnClickPendingIntent(R.id.control_next, pendingIntent)
intent = Intent(Constants.CMD_PROCESS_KEYCODE)
intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java)
@ -201,7 +209,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)
)
pendingIntent = PendingIntent.getBroadcast(context, 13, intent, 0)
pendingIntent = PendingIntent.getBroadcast(context, 13, intent, flags)
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent)
}
}

View File

@ -154,11 +154,14 @@ class DownloadService : Service() {
return notificationBuilder.build()
}
@SuppressLint("UnspecifiedImmutableFlag")
private fun getPendingIntentForContent(): PendingIntent {
val intent = Intent(this, NavigationActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
val flags = PendingIntent.FLAG_UPDATE_CURRENT
var flags = PendingIntent.FLAG_UPDATE_CURRENT
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// needed starting Android 12 (S = 31)
flags = flags or PendingIntent.FLAG_IMMUTABLE
}
intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
return PendingIntent.getActivity(this, 0, intent, flags)
}