1
0
mirror of https://github.com/ultrasonic/ultrasonic synced 2025-02-19 21:20:52 +01:00

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 = [ ext.versions = [
minSdk : 21, minSdk : 21,
targetSdk : 30, targetSdk : 31,
compileSdk : 31, compileSdk : 31,
] ]

View File

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

View File

@ -15,7 +15,6 @@
*/ */
package org.moire.ultrasonic.playback package org.moire.ultrasonic.playback
import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Intent import android.content.Intent
import androidx.media3.common.AudioAttributes import androidx.media3.common.AudioAttributes
@ -135,11 +134,14 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
.build() .build()
} }
@SuppressLint("UnspecifiedImmutableFlag")
private fun getPendingIntentForContent(): PendingIntent { private fun getPendingIntentForContent(): PendingIntent {
val intent = Intent(this, NavigationActivity::class.java) val intent = Intent(this, NavigationActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) .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) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
return PendingIntent.getActivity(this, 0, intent, flags) return PendingIntent.getActivity(this, 0, intent, flags)
} }

View File

@ -7,7 +7,6 @@
package org.moire.ultrasonic.provider package org.moire.ultrasonic.provider
import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider import android.appwidget.AppWidgetProvider
@ -164,7 +163,6 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
/** /**
* Link up various button actions using [PendingIntent]. * Link up various button actions using [PendingIntent].
*/ */
@SuppressLint("UnspecifiedImmutableFlag")
private fun linkButtons(context: Context, views: RemoteViews, playerActive: Boolean) { private fun linkButtons(context: Context, views: RemoteViews, playerActive: Boolean) {
var intent = Intent( var intent = Intent(
context, context,
@ -173,8 +171,13 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
if (playerActive) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true) if (playerActive) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
intent.action = "android.intent.action.MAIN" intent.action = "android.intent.action.MAIN"
intent.addCategory("android.intent.category.LAUNCHER") 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 = 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_coverart, pendingIntent)
views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent) views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent)
@ -185,7 +188,12 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT, Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) 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) views.setOnClickPendingIntent(R.id.control_play, pendingIntent)
intent = Intent(Constants.CMD_PROCESS_KEYCODE) intent = Intent(Constants.CMD_PROCESS_KEYCODE)
intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java) intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java)
@ -193,7 +201,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT, Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT) 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) views.setOnClickPendingIntent(R.id.control_next, pendingIntent)
intent = Intent(Constants.CMD_PROCESS_KEYCODE) intent = Intent(Constants.CMD_PROCESS_KEYCODE)
intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java) intent.component = ComponentName(context, MediaButtonIntentReceiver::class.java)
@ -201,7 +209,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
Intent.EXTRA_KEY_EVENT, Intent.EXTRA_KEY_EVENT,
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS) 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) views.setOnClickPendingIntent(R.id.control_previous, pendingIntent)
} }
} }

View File

@ -154,11 +154,14 @@ class DownloadService : Service() {
return notificationBuilder.build() return notificationBuilder.build()
} }
@SuppressLint("UnspecifiedImmutableFlag")
private fun getPendingIntentForContent(): PendingIntent { private fun getPendingIntentForContent(): PendingIntent {
val intent = Intent(this, NavigationActivity::class.java) val intent = Intent(this, NavigationActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) .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) intent.putExtra(Constants.INTENT_SHOW_PLAYER, true)
return PendingIntent.getActivity(this, 0, intent, flags) return PendingIntent.getActivity(this, 0, intent, flags)
} }