setOngoing(true) is not working in Oreo+ Notifications - notifications

I am creating a custom notification with channel_id and start it as foreground. I have background music playing .. My problem is when user swipe notification it disappears. I have also setOngoing(true). i want notification to stay when music is playing.
NOTE: It only happens in Oreo+. in lower versions it is working fine.
public void CustomNotification() {
remoteViews = new RemoteViews(getPackageName(), R.layout.player_noti_layout);
notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("default",
getString(R.string.player_channel),
NotificationManager.IMPORTANCE_LOW);
channel.enableVibration(true);
channel.enableLights(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.setDescription("Notification, Play/pause & Next/Prev");
notificationmanager.createNotificationChannel(channel);
}
builder = new NotificationCompat.Builder(this, "default");
Notification foregroundNote;
// Set icon
foregroundNote = builder.setSmallIcon(R.drawable.ic_radio)
.setLargeIcon(R.drawable.cool_1)
// Set ticker message
.setTicker(getResources().getString(R.string.app_name))
// Dismiss notification
.setAutoCancel(false)
.setOngoing(true)
.setContent(remoteViews)
.setContentTitle("title").
setContentText("text")
.build();
foregroundNote.flags |= Notification.FLAG_ONGOING_EVENT;
foregroundNote.flags |= Notification.FLAG_NO_CLEAR;
foregroundNote.contentView = remoteViews;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
startForeground(2, foregroundNote);
} else
notificationmanager.notify(2, foregroundNote);
}

In a few words, that's due to fragmentation and customization. Probably that phone has some kind of setting to configure that behavior. As someone said one day: Some phones are just -trash-. Don't waste your time trying to fix an issue for every possible phone.

Related

Mute iOS microphone input with ReactNative

I am using Agora's ReactNative library for a group calling project, I need the user to be able to mute/unmute his phone microphone. Currently there is only a function to muteLocalAudioStream which does mute the whole stream, that includes the background sounds, as the streamer can add background sound to the call.
For Android I managed to mute/unmute the microphone with the below hack:
#ReactMethod
public void muteMic(){
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
if (audioManager.isMicrophoneMute() == false) {
audioManager.setMicrophoneMute(true);
} else {
audioManager.setMicrophoneMute(false);
}
}
However, I couldn't do it for iOS, I appreciate your help on this.
You can change recording level with a call to
// volume: [0,100]
RtcEngine.adjustRecordingSignalVolume(volume)

Video event issue: User touching screen before time to play

Hi this question is for anyone who may be able to show me how to resolve this user issue. I have a script that plays a video with the user able pause and resume on touch. This was easy enough to do and works fine. At a certain point the script pauses the video for the user for a set time so the user has time to read the information on the screen. The intent is for them to be able to to resume playing the video after reading the information. If the user waits long enough, the touch to resume works fine. But, because some users read faster than others it is obvious I need to detect the touch even when the video was paused by the script - this is the part I need help with. Currently, if the video is paused by the script and the user touches the screen before the set time for the pause expires, the play button will show but pressing it to play will not resume the script until that time expires. I presume I need a listener inside the function the script used to pause the video. I am not quite sure the best way to handle that. Here is a snippet of my approach so far:
var myVideo = document.getElementById("myVideo");
function playPause() {
var el = document.getElementById("playButton");
if (myVideo.paused) {
myVideo.play();
el.className ="";
} else {
myVideo.pause();
el.className = "playButton";
}
}
myVideo.addEventListener("click", playPause, false);
var pause42 = function(){
if(this.currentTime >= 42 && !myVideo.paused) {
this.pause();
// remove the event listener after you paused the playback
this.removeEventListener("timeupdate",pause42);
}
};
myVideo.addEventListener("timeupdate", pause42);
Any help is appreciated!
FYI problem solved. Posting the answer here if it helps others.
var pause42 = function(){
if(this.currentTime >= 15 && !myVideo.paused) {
this.currentTime = 42;
this.pause();
// remove the event listener after you paused the playback
this.removeEventListener("timeupdate",pause42);
}
};
myVideo.addEventListener("timeupdate", pause42);

GCM Notification Title and Message in LockScreen (Android)

I want to show a GCM Notification containing a title, message, and a large icon in the Lock Screen. The image and the title will be coming from my app where the title is my app's name and the notification belong to one signal service.
I want to make the notification same as below notification in the picture.
This is my code:
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
GcmBroadcastReceiver.completeWakefulIntent(intent);
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
Bitmap small_Icon = getBitmapFromURL((String) extras.get(Config.SMALLICON_KEY));
Bitmap large_Icon = getBitmapFromURL((String) extras.get(Config.LARGEICON_KEY));
Bitmap Poster = getBitmapFromURL((String) extras.get(Config.BIGPICTURE_KEY));
String title = (String) extras.get(Config.TITLE_KEY);
String message = (String) extras.get(Config.MESSAGE_KEY);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon((R.drawable.ic_launcher))
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(Poster)
.setBigContentTitle(title)
.setSummaryText(message))
.setContentTitle(title)
.setContentText(message)
.setLargeIcon(large_Icon);
//////// Play Defult Notification Sound ////////
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
//////// End Play Defult Notification Sound ////////
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Log.d(TAG, "Notification sent successfully.");
}
What you are aiming to do is a visible Lock Screen Notification. As per the docs:
Setting Visibility
Your app can control the level of detail visible in notifications displayed on a secure lock screen. You call setVisibility() and specify one of the following values: VISIBILITY_PUBLIC, VISIBILITY_SECRET, VISIBILITY_PRIVATE.
Also found this Simple Tutorial on Lollipop Notifications that might be useful for you.

How to Handle The Notification (Shell_NotifyIcon) to perform Some action when user clicked on It?

Iam NewBie, I have Created Tray Icon for my Application
with
void createTrayIcon(LpSTR msg)
{
memset(&m_NID, 0 , sizeof(m_NID));
m_NID.cbSize = sizeof(m_NID);
// set tray icon ID
m_NID.uID = ID_SYSTEMTRAY ;
// set handle to the window that receives tray icon notifications
ASSERT(::IsWindow(GetSafeHwnd()));
m_NID.hWnd = GetSafeHwnd();
// set message that will be sent from tray icon to the window
m_NID.uCallbackMessage = WM_TRAYICON_EVENT;
StringCchCopy(m_NID.szInfo, ARRAYSIZE(m_NID.szTip),msg);
StringCchCopy(m_NID.szInfoTitle, ARRAYSIZE(m_NID.szInfoTitle), L"DuOS");
// fields that are being set when adding tray icon
m_NID.uFlags = NIF_MESSAGE|NIF_ICON|NIF_INFO;
// set image
m_NID.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
if(!m_NID.hIcon)
return FALSE;
return Shell_NotifyIcon(NIM_ADD, &m_NID);
}
I Am Showing the Notifications By Using
Shell_NotifyIcon(NIM_MODIFY , &m_NID);
My problem is I want to handle that Notification i.e, If user clicks on that
Notification I need to do some action, How to achieve this
I am trying for this from last two days I had Googled Lot of times and searched lot of blogs But I cant, Anyone Please Help me Out
Finally I Got the Answer ,
there was a NIN_BALOONUSERCLICK flag was there, if User clicks on Baloon it will return this Flag...

windows 8 metro app - toast notification

I am developing a Windows 8 metro-style application using toast notification. (C# + xaml combination)
I looked into MS metro style sample code and tried to apply it to my project,
looks like I used the code exactly the same way, but I don't know why it is not working..
(There is no error, it builds successfully but just doesn't work.)
What I'm trying to do is very simple:
There is a button.
When the button_click event occurs, I'd like to pop a toast notification.
This is what I did:
namespace Application1
{
public sealed partial class BlankPage : Page
{
public BlankPage()
{
this.InitializeComponent();
Scenario2Init();
}
void Scenario2Init()
{
toastTest.Click += (sender, e) => { ToastAlarm(true); };
}
void ToastAlarm(bool loopAudio)
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
// Toasts can optionally be set to long duration by adding the 'duration' attribute
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
// This XmlNodeList will have two items since the template we are using has two text fields.
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Long Duration Toast"));
XmlElement audioElement = toastXml.CreateElement("audio");
if (loopAudio)
{
// Long-duration Toasts can optionally loop audio using the 'loop' attribute
audioElement.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Alarm");
audioElement.SetAttribute("loop", "true");
stringElements.Item(1).AppendChild(toastXml.CreateTextNode("Looping audio"));
}
else
{
audioElement.SetAttribute("src", "ms-winsoundevent:Notification.IM");
}
toastNode.AppendChild(audioElement);
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
//Scenario2OutputText.Text = toastXml.GetXml();
}
}
}
If I click the button, nothing happens. Why?
Your code looks correct to me; I don't have Win8 with me here right now so I can't test it. However, you may want to check your app's manifest if you enabled Toast or not in the "Toast Capable" field in VS. Hope this helps.
Did you enable "Toast capable" in Package.appxmanifest?
I think, there are two reasons,
First may be relating to toast capability of your application. For this set ToastCapable="true" in your Package.appxmanifest
Second one is run application in Local Machine rather than Simulator. I found that Simulator is not able to produce Toast notification.
i think you can just use Xml String
// Create the toast content by direct string manipulation.
// See the Toasts SDK Sample for other ways of generating toasts.
string toastXmlString =
"<toast duration=\"long\">\n" +
"<visual>\n" +
"<binding template=\"ToastText02\">\n" +
"<text id=\"1\">Alarms Notifications SDK Sample App</text>\n" +
"<text id=\"2\">" + alarmName + "</text>\n" +
"</binding>\n" +
"</visual>\n" +
"<commands scenario=\"alarm\">\n" +
"<command id=\"snooze\"/>\n" +
"<command id=\"dismiss\"/>\n" +
"</commands>\n" +
"<audio src=\"ms-winsoundevent:Notification.Looping.Alarm5\" loop=\"true\" />\n" +
"</toast>\n";