android-notifications

Does updating a Notification remove a Service's foreground status?

耗尽温柔 提交于 2019-11-30 14:46:25
问题 In my app, I place my Service in the foreground to prevent it from being killed by using: startForeground(NOTIFY_ID, notification); This also displays the notification to the user (which is great). The problem is that later I need to update the notification. So I use the code: notification.setLatestEventInfo(getApplicationContext(), someString, someOtherString, contentIntent); mNotificationManager.notify(NOTIFY_ID, notification); The question then is: will doing this knock the Service out of

How to increase the ringer & notification volume programmatically in android

和自甴很熟 提交于 2019-11-30 14:44:17
I am trying to enable the ringer normal mode and increase the volume programmatically. AudioManager mobilemode = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); // int streamMaxVolume = mobilemode.getStreamMaxVolume(AudioManager.STREAM_RING); switch (mobilemode.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL); mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0); break; case AudioManager.RINGER_MODE_VIBRATE: Log.i("MyApp",

Android P Beta - AlarmManager Notifications not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 14:02:26
I'm testing my application on Android P beta release 4. My app's targetSdkVersion is 27 It has been observed that alarm manager notifications are not working as expected. I'm using below code to set the notifications - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmIntentBuilder.buildPendingIntent(context, uri)); } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis,

Android notification is not showing it's content when app is not running

本小妞迷上赌 提交于 2019-11-30 12:48:17
问题 Here is my interesting problem. Android notification that comes from GCM is not showing title and content ( just shows App Name, and when click, open the MainActivity) when app is not running. But when the app is open, it's showing successfully title and content. What can be the problem? It was running without problem and I didn't change anything. Manifest: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

Single Notification for multiple Foreground Services using startForeground() call

痴心易碎 提交于 2019-11-30 12:30:06
I have an app that has two services. One is for showing UI for floating (overlay) on other apps using WindowManager . The other is for Location Tracking using GooglePlayAPI . My app always runs these services. I want these services not to be killed by the OS. So I call Service.startForeground() . However there are two notifications in the notification drawer. Is there a way to use a single notification for both services? Yes, it is possible. If we take a look at Service.startForeground() signature, it accept both notification id & the notification itself ( see documentation ). Hence, if we

Is there a straightforward way to stop a service in response to a user clicking a notification?

雨燕双飞 提交于 2019-11-30 12:23:30
I'd like the following behavior: The user clicks a notification and Android stops my Service. The problem is that stopping a Service requires a call to stopService and I cannot easily create a PendingIntent that does that. So the only way I found to do this is to have my Service receive a special Intent extra that causes the Service to call stopSelf and stop. Is there a simpler way to directly cancel a Service from a notification click? You could create a simple BroadcastReceiver that does the stopService() call, and use a getBroadcast() PendingIntent to trigger it. That BroadcastReceiver

Does updating a Notification remove a Service's foreground status?

霸气de小男生 提交于 2019-11-30 12:20:18
In my app, I place my Service in the foreground to prevent it from being killed by using: startForeground(NOTIFY_ID, notification); This also displays the notification to the user (which is great). The problem is that later I need to update the notification. So I use the code: notification.setLatestEventInfo(getApplicationContext(), someString, someOtherString, contentIntent); mNotificationManager.notify(NOTIFY_ID, notification); The question then is: will doing this knock the Service out of it's special foreground status? In this answer , CommonsWare indicates that this behavior is possible,

How to know whether Notifications are enabled or not for an application in android?

你。 提交于 2019-11-30 11:51:21
I've a ListView which has the list of installed applications and for each application, I need to know whether the notifications are enabled or not. Currently I'm using below code to know if the notifications are enabled: appOpsClass = Class.forName(AppOpsManager.class.getName()); Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); int value = (int)opPostNotificationValue.get(Integer.class); return ((int)checkOpNoThrowMethod.invoke(mAppOps,value,

Lollipop Notification setVisibility() Does Not Work?

自作多情 提交于 2019-11-30 11:13:34
I am trying to write a demo of using setVisibility() to control what shows up on the Android 5.0 lockscreen for a Notification . However, there seems to be no effect: the default VISIBILITY_PRIVATE still shows the private Notification , not its public counterpart VISIBILITY_SECRET notifications still show up on the lockscreen IOW, everything behaves as though VISIBILITY_PUBLIC were in force, at least when I test on a Nexus 7 running the Android 5.0 image we were given shortly after Android 5.0 was released (build LPX13D). So I don't know if the problem is tied to my code, to this device, or to

How can I avoid blinking notification update while changing button

雨燕双飞 提交于 2019-11-30 11:10:29
I have a Notification, which supports play,pause forward and back. private static Notification createNotification(String interpret, String title, boolean paused) { // if (builder == null) builder = new NotificationCompat.Builder(context); builder.setPriority(Notification.PRIORITY_MAX); builder.setAutoCancel(false); builder.setContentTitle(title); builder.setContentText(interpret); builder.setOngoing(true); builder.setOnlyAlertOnce(true); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentIntent(PendingIntent.getActivity(context, 9, new Intent(context, ApplicationActivity.class),