Skip to content

Commit 3f37d95

Browse files
committed
fix notif and toolboar
1 parent 4f5a5ae commit 3f37d95

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

app/src/main/AndroidManifest.xml

-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@
7575
<activity android:exported="true" android:name="org.glpi.inventory.agent.ui.ActivityDetailServer">
7676
<intent-filter>
7777
<action android:name="android.intent.action.VIEW"/>
78-
7978
<category android:name="android.intent.category.DEFAULT"/>
8079
<category android:name="android.intent.category.BROWSABLE"/>
81-
8280
<data android:host="glpi-project.github.io" android:pathPrefix="/android-inventory-agent/deeplink"/>
8381
<data android:scheme="http"/>
8482
<data android:scheme="https"/>

app/src/main/java/org/glpi/inventory/agent/broadcast/InventoryJobScheduler.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646
import android.content.Intent;
4747
import android.content.SharedPreferences;
4848
import android.graphics.Color;
49+
import android.net.Uri;
50+
import android.os.Build;
4951
import android.os.Handler;
5052
import android.os.HandlerThread;
5153
import android.preference.PreferenceManager;
54+
import android.provider.Settings;
5255

5356
import androidx.core.app.NotificationCompat;
5457

@@ -164,25 +167,36 @@ private void showPersistentNotification() {
164167
manager.createNotificationChannel(chan);
165168
}
166169

170+
// intent to redirect to notificaition ettings
171+
/*Intent notificationIntent;
172+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
173+
notificationIntent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
174+
notificationIntent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
175+
notificationIntent.putExtra(Settings.EXTRA_CHANNEL_ID, NOTIFICATION_CHANNEL_ID);
176+
notificationIntent.putExtra("app_package", getPackageName());
177+
notificationIntent.putExtra("app_uid", getApplicationInfo().uid);
178+
notificationIntent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
179+
} else {
180+
notificationIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
181+
notificationIntent.setData(Uri.parse("package:" + getPackageName()));
182+
}
183+
PendingIntent notificationPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);*/
184+
185+
167186
Intent appIntent = new Intent(this, ActivityMain.class);
168187
appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
169188
PendingIntent appIntentRedirect = PendingIntent.getActivity(this, 0, appIntent, PendingIntent.FLAG_IMMUTABLE);
170189

171-
Intent notificationIntent = new Intent();
172-
notificationIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
173-
notificationIntent.putExtra("app_package", getPackageName());
174-
notificationIntent.putExtra("app_uid", getApplicationInfo().uid);
175-
PendingIntent notificationIntentRedirect = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
176-
177190
Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
178-
.setOngoing(true)
191+
.setOngoing(false)
179192
.setSmallIcon(R.drawable.ic_stat)
180193
.setContentTitle(getString(R.string.app_is_running))
181-
.setContentText(getString(R.string.agent_description)) // Add a short text
194+
.setContentText(getString(R.string.agent_description))
182195
.setCategory(Notification.CATEGORY_SERVICE)
196+
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
183197
.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.app_is_running_extend)))
184198
.setContentIntent(appIntentRedirect)
185-
.addAction(R.drawable.ic_about, getString(R.string.disable_notification), notificationIntentRedirect)
199+
//.addAction(R.drawable.ic_stat, getString(R.string.disable_notification), notificationPendingIntent)
186200
.build();
187201

188202
int notificationId = 1;

app/src/main/java/org/glpi/inventory/agent/ui/ActivityMain.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ public class ActivityMain extends AppCompatActivity
106106
private TextView textview_settings, textview_scheduler;
107107
InventoryJobScheduler alarm = new InventoryJobScheduler();
108108

109-
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
110-
@Override
111-
public void onReceive(Context context, Intent intent) {
112-
String strTime = intent.getStringExtra("time");
113-
if (sharedPreferences.getBoolean("autoStartInventory", false)) {
114-
toolbar.setSubtitle(strTime);
115-
} else {
116-
toolbar.setSubtitle("");
117-
}
118-
}
119-
};
120-
121109
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
122110
@Override
123111
public void onReceive(Context context, Intent intent) {
@@ -143,6 +131,12 @@ protected void onStart() {
143131
} else {
144132
registerReceiver(appRestrictionChange, restrictionsFilter);
145133
}
134+
135+
if (sharedPreferences.getBoolean("autoStartInventory", false)) {
136+
toolbar.setSubtitle(sharedPreferences.getString("timeInventory", "Week"));
137+
} else {
138+
toolbar.setSubtitle("autoStartInventory not set");
139+
}
146140
}
147141

148142

0 commit comments

Comments
 (0)