Skip to content

Commit 5971065

Browse files
committed
feat: open UI when create service
1 parent 5643a83 commit 5971065

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
<application>
1212

1313
<!-- The main service, handles playback, playlists and media buttons -->
14-
<service android:name="com.doublesymmetry.trackplayer.service.MusicService" android:enabled="true" android:exported="true" android:foregroundServiceType="mediaPlayback">
14+
<service
15+
android:name="com.doublesymmetry.trackplayer.service.MusicService"
16+
android:enabled="true"
17+
android:exported="true"
18+
android:foregroundServiceType="mediaPlayback">
1519
<intent-filter>
1620
<action android:name="android.intent.action.MEDIA_BUTTON" />
1721
<action android:name="android.media.browse.MediaBrowserService" />
1822
</intent-filter>
1923
</service>
20-
24+
2125
<meta-data android:name="com.google.android.gms.car.application"
2226
android:resource="@xml/automotive_app_desc"/>
2327
</application>

android/src/main/java/com/doublesymmetry/trackplayer/HeadlessJsMediaService.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import android.content.BroadcastReceiver;
1212
import android.content.Context;
1313
import android.content.Intent;
14+
import android.net.Uri;
1415
import android.os.IBinder;
1516
import android.os.PowerManager;
17+
import android.util.Log;
18+
1619
import androidx.annotation.Nullable;
1720
import androidx.media.MediaBrowserServiceCompat;
1821
import com.facebook.infer.annotation.Assertions;
@@ -45,7 +48,9 @@ public abstract class HeadlessJsMediaService extends MediaBrowserServiceCompat i
4548

4649
private final Set<Integer> mActiveTasks = new CopyOnWriteArraySet<>();
4750
private static @Nullable PowerManager.WakeLock sWakeLock;
48-
51+
52+
53+
4954
@Override
5055
public int onStartCommand(Intent intent, int flags, int startId) {
5156
HeadlessJsTaskConfig taskConfig = getTaskConfig(intent);
@@ -87,8 +92,19 @@ public static void acquireWakeLockNow(Context context) {
8792
public @Nullable IBinder onBind(Intent intent) {
8893
return super.onBind(intent);
8994
}
90-
91-
/**
95+
96+
@Override
97+
public void onCreate() {
98+
Intent openAppIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
99+
openAppIntent.setData(Uri.parse("trackplayer://service-created"));
100+
openAppIntent.setAction(Intent.ACTION_VIEW);
101+
openAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
102+
startActivity(openAppIntent);
103+
super.onCreate();
104+
105+
}
106+
107+
/**
92108
* Start a task. This method handles starting a new React instance if required.
93109
*
94110
* <p>Has to be called on the UI thread.

android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.doublesymmetry.trackplayer.service
22

33
import android.app.*
4+
import android.content.ComponentName
45
import android.content.Context
56
import android.content.Intent
67
import android.content.pm.ServiceInfo
@@ -53,6 +54,12 @@ class MusicService : HeadlessJsMediaService() {
5354
MediaConstants.DESCRIPTION_EXTRAS_VALUE_CONTENT_STYLE_LIST_ITEM,
5455
MediaConstants.DESCRIPTION_EXTRAS_VALUE_CONTENT_STYLE_LIST_ITEM)
5556

57+
@ExperimentalCoroutinesApi
58+
override fun onCreate() {
59+
Timber.tag("GVA-RNTP").d("RNTP musicservice created.")
60+
super.onCreate()
61+
}
62+
5663
/**
5764
* Use [appKilledPlaybackBehavior] instead.
5865
*/
@@ -82,6 +89,7 @@ class MusicService : HeadlessJsMediaService() {
8289
parentMediaId: String,
8390
result: Result<List<MediaItem>>
8491
) {
92+
Timber.tag("GVA-RNTP").d("RNTP received loadChildren req: %s", parentMediaId)
8593
result.sendResult(mediaTree[parentMediaId])
8694
}
8795

0 commit comments

Comments
 (0)