Skip to content

Commit df49fac

Browse files
committed
Update bg notification, show steps in the allow button
1 parent bfbfa0a commit df49fac

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

OpenPods/app/src/main/java/com/dosse/airpods/IntroActivity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void initScreen () {
7575

7676
switch (step) {
7777
case 1:
78-
msg.setText(String.format(Locale.getDefault(), "Step %d/%d: %s", step, numOfSteps, getString(R.string.intro_bat_perm)));
78+
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_bat_perm)));
7979
btn.setOnClickListener(view -> {
8080
Intent intent = new Intent();
8181
getSystemService(Context.POWER_SERVICE);
@@ -85,16 +85,18 @@ private void initScreen () {
8585
});
8686
break;
8787
case 2:
88-
msg.setText(String.format(Locale.getDefault(), "Step %d/%d: %s", step, numOfSteps, getString(R.string.intro_loc1_perm)));
88+
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_loc1_perm)));
8989
btn.setOnClickListener(view -> requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 101)); // Location (for BLE)
9090
break;
9191
case 3:
92-
msg.setText(String.format(Locale.getDefault(), "Step %d/%d: %s", step, numOfSteps, getString(R.string.intro_loc2_perm)));
92+
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_loc2_perm)));
9393
btn.setOnClickListener(view -> {
9494
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) requestPermissions(new String[] {Manifest.permission.ACCESS_BACKGROUND_LOCATION}, 102);
9595
});
9696
break;
9797
}
98+
99+
runOnUiThread(() -> btn.setText(String.format(Locale.getDefault(), "%s (%d/%d)", getString(R.string.intro_allow), step, numOfSteps)));
98100
}
99101

100102
}

OpenPods/app/src/main/java/com/dosse/airpods/PodsService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public void onCreate () {
420420
super.onCreate();
421421

422422
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
423-
startForeground(101, createNotification());
423+
startForeground(101, createBackgroundNotification());
424424

425425
IntentFilter intentFilter = new IntentFilter();
426426
intentFilter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
@@ -587,13 +587,14 @@ public int onStartCommand (Intent intent, int flags, int startId) {
587587
return START_STICKY;
588588
}
589589

590-
// Only for API30+
590+
// Foreground service background notification (confusing I know).
591+
// Only enabled for API30+
591592
@RequiresApi(api = Build.VERSION_CODES.O)
592-
private Notification createNotification () {
593+
private Notification createBackgroundNotification () {
593594
final String notChannelID = "FOREGROUND_ID";
594595

595596
NotificationManager notManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
596-
NotificationChannel notChannel = new NotificationChannel(notChannelID, "Background Notification", NotificationManager.IMPORTANCE_MIN);
597+
NotificationChannel notChannel = new NotificationChannel(notChannelID, getString(R.string.bg_noti_channel), NotificationManager.IMPORTANCE_LOW);
597598

598599
notManager.createNotificationChannel(notChannel);
599600

@@ -602,12 +603,12 @@ private Notification createNotification () {
602603
.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName())
603604
.putExtra(Settings.EXTRA_CHANNEL_ID, notChannelID);
604605

605-
PendingIntent notPendingIntent = PendingIntent.getActivity(this, 1110, notIntent,0);
606+
PendingIntent notPendingIntent = PendingIntent.getActivity(this, 1110, notIntent, 0);
606607

607608
Notification.Builder builder = new Notification.Builder(this, notChannelID)
608609
.setSmallIcon(R.drawable.pod_case)
609-
.setContentTitle("Running in the background")
610-
.setContentText("Click to open notification Settings")
610+
.setContentTitle(getString(R.string.bg_noti_title))
611+
.setContentText(getString(R.string.bg_noti_text))
611612
.setContentIntent(notPendingIntent)
612613
.setOngoing(true);
613614

OpenPods/app/src/main/res/values/strings.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
<resources xmlns:tools="http://schemas.android.com/tools">
33
<string name="app_name" translatable="false">OpenPods</string>
44

5+
<string name="bg_noti_channel" translatable="false">Background Notification</string>
6+
<string name="bg_noti_title" tools:ignore="MissingTranslation">Running in the background</string>
7+
<string name="bg_noti_text" tools:ignore="MissingTranslation">Click to open notification settings</string>
8+
59
<string name="intro_title">This app lets you check the status of your AirPods on any Android device</string>
610
<string name="intro_message">To operate, we need permission to use Bluetooth LE (Location) and permission to run in background</string>
711
<string name="intro_allow">Allow</string>
8-
<string name="intro_step" translatable="false">Step</string>
9-
<string name="intro_bat_perm" translatable="false">Battery Optimization</string>
10-
<string name="intro_loc1_perm" translatable="false">Location Permission</string>
11-
<string name="intro_loc2_perm" translatable="false">Background Location Permission</string>
12+
<string name="intro_step" tools:ignore="MissingTranslation">Step</string>
13+
<string name="intro_bat_perm" tools:ignore="MissingTranslation">Battery Optimization</string>
14+
<string name="intro_loc1_perm" tools:ignore="MissingTranslation">Location Permission</string>
15+
<string name="intro_loc2_perm" tools:ignore="MissingTranslation">Background Location Permission</string>
1216

1317
<string name="main_description">The app will show a notification when your AirPods are connected</string>
1418
<string name="hide_message">You can hide this app if you want</string>
@@ -35,7 +39,7 @@
3539

3640
<string name="about_dev">Developed by Federico Dossena and Itai Levin</string>
3741
<string name="website">Website</string>
38-
<string name="github" translatable="false">Github</string>
42+
<string name="github" tools:ignore="MissingTranslation">Github</string>
3943
<string name="donate">Donate</string>
4044
<string name="fdroid" translatable="false">F-Droid</string>
4145
</resources>

0 commit comments

Comments
 (0)