package de.ullisroboterseite.ursai2mediatest; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import android.app.PendingIntent; import android.content.*; import android.os.Build; import android.util.Log; import android.support.v4.media.session.MediaSessionCompat; import androidx.media.session.MediaButtonReceiver; // Autor: https://UllisRoboterSeite.de // Version 1.0 (2025-03-12) // ------------------------- // - Basis-Version // @DesignerComponent(version = 1, // versionName = UrsMediaTest.VersionName, // dateBuilt = UrsMediaTest.dateBuilt, // description = "AI2 Media Notification Test.", // category = com.google.appinventor.components.common.ComponentCategory.EXTENSION, // nonVisible = true, // iconName = "aiwebres/icon.png") @UsesLibraries(libraries = "androidx.media.jar") @SimpleObject(external = true) public class UrsMediaTest extends AndroidNonvisibleComponent { static final String VersionName = "1.0.7"; static final String dateBuilt = "2025-02-27"; static final String LOG_TAG = "MEDIA"; MediaSessionCompat mediaSession = null; public UrsMediaTest(ComponentContainer container) { super(container.$form()); try { Log.d(LOG_TAG, "============= UrsMediaTest ctor " + VersionName); ComponentName mbrComponent = MediaButtonReceiver.getMediaButtonReceiverComponent(form); Intent mediaButtonIntent = new Intent("android.intent.action.MEDIA_BUTTON"); mediaButtonIntent.setComponent(mbrComponent); PendingIntent mbrIntent = PendingIntent.getBroadcast(form, 0, mediaButtonIntent, Build.VERSION.SDK_INT >= 31 ? PendingIntent.FLAG_IMMUTABLE : 0); mediaSession = new MediaSessionCompat(form, "MediaNotificationSession", mbrComponent, mbrIntent); Log.d(LOG_TAG, "ctor done"); } catch (Exception e) { Log.d(LOG_TAG, "Exception: " + e.toString()); } } }