diff options
author | Max Kellermann <max@musicpd.org> | 2020-04-02 18:02:10 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-04-02 18:02:10 +0200 |
commit | 12b97bbe3896df558b3b8f52e8d9d495058aa996 (patch) | |
tree | 4430cf6fcd89a7c9d389f1f903c927b6d5297d1a /android | |
parent | 7d7bd51bc0a4748593e774decc91a1dbc939fd90 (diff) | |
parent | 5ccfcffcc124e406233359fe8fe65b704b98b8c8 (diff) |
Merge tag 'v0.21.22'
release v0.21.22
Diffstat (limited to 'android')
-rw-r--r-- | android/AndroidManifest.xml | 19 | ||||
-rw-r--r-- | android/src/Main.java | 49 | ||||
-rw-r--r-- | android/src/Settings.java | 3 |
3 files changed, 64 insertions, 7 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 83286b0b7..4dcdba4fd 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -2,18 +2,25 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.musicpd" android:installLocation="auto" - android:versionCode="44" - android:versionName="0.21.21"> + android:versionCode="45" + android:versionName="0.21.22"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/> + <uses-feature android:name="android.software.leanback" + android:required="false" /> + <uses-feature android:name="android.hardware.touchscreen" + android:required="false" /> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <application android:allowBackup="true" android:icon="@drawable/icon" + android:banner="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Settings" android:label="@string/app_name"> @@ -22,6 +29,14 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:name=".Settings" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> + </intent-filter> + </activity> + <receiver android:name=".Receiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> diff --git a/android/src/Main.java b/android/src/Main.java index 57abee56c..b0c63136a 100644 --- a/android/src/Main.java +++ b/android/src/Main.java @@ -21,6 +21,7 @@ package org.musicpd; import android.annotation.TargetApi; import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.ComponentName; @@ -35,6 +36,9 @@ import android.os.RemoteException; import android.util.Log; import android.widget.RemoteViews; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + public class Main extends Service implements Runnable { private static final String TAG = "Main"; private static final String REMOTE_ERROR = "MPD process was killed"; @@ -156,11 +160,36 @@ public class Main extends Service implements Runnable { sendMessage(MSG_SEND_STATUS, mStatus, 0, mError); } + private Notification.Builder createNotificationBuilderWithChannel() { + final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager == null) + return null; + + final String id = "org.musicpd"; + final String name = "MPD service"; + final int importance = 3; /* NotificationManager.IMPORTANCE_DEFAULT */ + + try { + Class<?> ncClass = Class.forName("android.app.NotificationChannel"); + Constructor<?> ncCtor = ncClass.getConstructor(String.class, CharSequence.class, int.class); + Object nc = ncCtor.newInstance(id, name, importance); + + Method nmCreateNotificationChannelMethod = + NotificationManager.class.getMethod("createNotificationChannel", ncClass); + nmCreateNotificationChannelMethod.invoke(notificationManager, nc); + + Constructor nbCtor = Notification.Builder.class.getConstructor(Context.class, String.class); + return (Notification.Builder) nbCtor.newInstance(this, id); + } catch (Exception e) + { + Log.e(TAG, "error creating the NotificationChannel", e); + return null; + } + } + private void start() { if (mThread != null) return; - mThread = new Thread(this); - mThread.start(); final Intent mainIntent = new Intent(this, Settings.class); mainIntent.setAction("android.intent.action.MAIN"); @@ -168,13 +197,25 @@ public class Main extends Service implements Runnable { final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); - Notification notification = new Notification.Builder(this) - .setContentTitle(getText(R.string.notification_title_mpd_running)) + Notification.Builder nBuilder; + if (Build.VERSION.SDK_INT >= 26 /* Build.VERSION_CODES.O */) + { + nBuilder = createNotificationBuilderWithChannel(); + if (nBuilder == null) + return; + } + else + nBuilder = new Notification.Builder(this); + + Notification notification = nBuilder.setContentTitle(getText(R.string.notification_title_mpd_running)) .setContentText(getText(R.string.notification_text_mpd_running)) .setSmallIcon(R.drawable.notification_icon) .setContentIntent(contentIntent) .build(); + mThread = new Thread(this); + mThread.start(); + startForeground(R.string.notification_title_mpd_running, notification); startService(new Intent(this, Main.class)); } diff --git a/android/src/Settings.java b/android/src/Settings.java index af3008be5..4650bbce6 100644 --- a/android/src/Settings.java +++ b/android/src/Settings.java @@ -105,12 +105,13 @@ public class Settings extends Activity { else mRunButton.setChecked(false); mFirstRun = true; + mTextStatus.setText(""); break; case MSG_STARTED: Log.d(TAG, "onStarted"); mRunButton.setChecked(true); mFirstRun = true; - mTextStatus.setText("CAUTION: this version is EXPERIMENTAL!"); // XXX + mTextStatus.setText("MPD service started"); break; case MSG_LOG: if (mLogListArray.size() > MAX_LOGS) |