how to do real time notification in my (own)app? - android-notifications

i am new to android. i need develop notification to my application. i have seen gcm (android hive) example and simple example of notification.
i was confused with that example. please guide me how to do real time notication?
mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nb = new NotificationCompat.Builder(this);
nb.setSmallIcon(R.drawable.ic_action_mail_add);
nb.setTicker("hi");
nb.setContentTitle("mail");
BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_action_mail);
Bitmap b= bd.getBitmap();
nb.setLargeIcon(b);
nb.setContentText("haii..");
nb.setContentInfo("3 unread");
nb.setAutoCancel(true);
Intent in = new Intent(this,NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
nb.setContentIntent(pi);

Related

Xamarin Plugin.BLE // I can't pull data

There is a device that measures tire tread depth and air pressure.
I made a connection but I can't pull data. Can you direct me on how to do it?
I pulled data using Android DLLs but failed with plugin.ble.
Note: The state in the device object disconnect after a certain time. I do not know the reason.
Source code I wrote
Part-1
bluetoothBLE = CrossBluetoothLE.Current;
adapter = CrossBluetoothLE.Current.Adapter;
list = new ObservableCollection();
DevicesList.ItemsSource = list;
Part-2
adapter.ScanTimeout = 10000;
adapter.ScanMode = ScanMode.Balanced;
adapter.DeviceDiscovered += (obj, a) =>
{
if (!list.Contains(a.Device))
list.Add(a.Device);
};
await adapter.StartScanningForDevicesAsync();
Part-3
device = DevicesList.SelectedItem as IDevice;
await adapter.StopScanningForDevicesAsync();
var connectParams = new ConnectParameters(true, true);
await adapter.ConnectToDeviceAsync(device, connectParams);
Part-4
var xservices = await device.GetServicesAsync();
var xservice = await device.GetServiceAsync(xservices[0].Id);
var Characteristic = await xservice.GetCharacteristicsAsync();
var xxxcharacteristicread = await xservice.GetCharacteristicAsync(xitem.Id);
var c = await xxxcharacteristicread.ReadAsync();
Version of the Plugin: 2.1.1
Platform: iOS 10.1 / Android 7.0
Device: samsung note 5 /i Phone 7

I had stored values of radio group in shared preference now I want to use that values for notification in android

For example if user selects radio button for vibrate off, then on notification, vibrate must be turned off using NotificationCompat.Builder
Can anyone give me an idea?
Its simple.
1.Before display Notification, Check the Vibrate is ON or OFF with the help of Shared Preferences.
SharedPreferences settings;
settings = getSharedPreferences("PREFS_NAME", 0); //Initialize SharedPreferences
Boolean CheckVibration = settings.getBoolean("CheckVibration", true);
//checks the vibration is ON or OFF through Sharedpreferences
2. Display the Notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle(getString(R.string.app_name));
mBuilder.setContentText("Notification Testing!");
if(CheckVibration){
long[] v = {100,200}; //The first index of array is number of milliseconds to wait before turning the vibrator on and the second index is number of millisecond to vibrate before turning it off
mBuilder.setVibrate(v); // if vibration is ON by RadioGroup, It will be Vibrate
}
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notifiid, mBuilder.build());
3. Do not forget to allow VIBRATE permission in AndroidManifest.xml.
<uses-permission android:name="android.permission.VIBRATE" />
Happy Coding :)

Custome notification sound is playing only if i have breakpoint windows universal 8.1

Hi when push notification is received i am displaying toast notification. i have issue that is if i have break point in below function then and then only custom notification sound is playing else notification sound is not playing.I thought might be audio is not loading so i added Task.delay for 2 sec/5 sec but no luck. What could be the issue..
public static void AddTostNotification(String xmlDocument)
{
List<string> messageSection = PushNotificationHelper.GetMessageAndLandingPage(xmlDocument);
ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode(messageSection[0]));
// toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("launch", messageSection[1]);
XmlElement audio = toastXml.CreateElement("audio");
audio.SetAttribute("src", "ms-appx:///Assets/Guitar.wav");
toastNode.AppendChild(audio);
//launch tost immediatly
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
i got it, It was threading issue,
//var ignored = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
//{
PushNotificationHelper.AddTostNotification(notificationContent);
//});

Enter in my application when i click on the notification in the notifications bar

In my application the user can decide if show the notifications or not through a preferences screen. Well the notification works but i would that clicking on the notification i would be able to enter in my application. This is my code:
#SuppressLint("NewApi")
private void checkPref(Intent intent){
this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
SharedPreferences myPref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
boolean pref_opt1 = myPref.getBoolean("firstDependent", false);
int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
if (pref_opt1){
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Battery Informations")
.setContentText("Battery level"+" "+level+"%")
.setSmallIcon(R.drawable.icon_small_not)
//.setLargeIcon(aBitmap)
.setTicker(level+"%")
.build();
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent(MainActivity.this, MainActivity.class);
PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
notifi.notify(215,notification);
} else {
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notifi.cancel(215);
}
}
I thought the PendingIntent did this function but nothing happen. How can i do it?
You need to add the pending intent to the Notification using setContentIntent().
See also the documentation for Notification.contentIntent; in particular note that you'll need FLAG_ACTIVITY_NEW_TASK on the Intent, and also make sure that your MainActivity is declared in AndroidManifest.xml so the notification manager (actually, the System UI) can see it.

NetStream not sending audio on second Call flex

I am trying to build a video conferencing application between two people. the problem I am facing is that I attach the video and mic to my stream and publish it. The first time a call is made the audio is transferred alongwith the video but when i end the call and call again this time i can see is only video and no audio is transferred in the stream. I debugged the application and mic and video are being attached to the stream. Cant figure out how to end this. Any help will be highly appreciated. Here is a bit of my code. Thank you.
camera = Camera.getCamera();
mic = Microphone.getMicrophone();
mic.setLoopBack(false); // prevent input from being routed back to local speakers - helps reduce feedback in some conditions
mic.setUseEchoSuppression(true);
camera.setMode(320,240,15);
camera.setQuality(65536,75);
// setup out going stream
var conn:NetConnection = Connection.getConnection().conn;
outStream = new NetStream(conn);
outStream.attachAudio(mic);
outStream.attachCamera(camera);
outStream.publish(appState.userProfile.username);
// setup in coming stream
inStream = new NetStream(conn);
inStream.play(appState.callingUser.username);
inStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
//inStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandlerForInStream);
and here is the endCall function.
if(camera!=null || mic != null)
{
outStream.attachCamera(null);
outStream.attachAudio(null);
outVideo.attachCamera(null);
inStream.close();
outStream.close();
camera = null;
mic = null;
inVideo = null;
outVideo = null;
inStream = null;
outStream = null;
if (newStream)
{
newStream.close();
newStream = null;
}
}

Resources