void createNotification(string title, string desc) { Android.Support.V4.App.NotificationCompat.Builder builder = new Android.Support.V4.App.NotificationCompat.Builder(this); var uiIntent = new Intent(this, typeof(MainActivity)); var notification1 = builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0)).SetSmallIcon(Resource.Drawable.Icon).SetTicker(desc).SetWhen(DateTime.Now.Millisecond).SetAutoCancel(true).SetContentTitle(title).SetContentText(desc).Build(); var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // var notification = new Notification(Resource.Drawable.Icon, title); // notification.Flags = NotificationFlags.AutoCancel; // notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0)); notificationManager.Notify(1, notification1); }
//public static void ShowOkAlert(Context context,string Message) //{ // AlertDialog.Builder alert = new AlertDialog.Builder(context); // alert.SetMessage(Message); // alert.SetPositiveButton("Ok", (senderAlert, args) => { // }); // Dialog dialog = alert.Create(); // dialog.Show(); //} //Download from url------------------------------------------ public static async void DownLoadSource(string url, Java.IO.File _appDirectory, Java.IO.File newFile, string filePath, Context context, string FileName, int notificationId) { // ShowToast(context, context.Resources.GetString(Resource.String.downloading) + Newsrc); var NotificationId = notificationId; string localPath; try { System.Uri uri = new System.Uri(url); WebClient webClient = new WebClient(); string localFileName; webClient.DownloadDataAsync(uri); Log.Debug("tag", "File to download = " + newFile.ToString()); MimeTypeMap mime = MimeTypeMap.Singleton; String ext = newFile.Name.Substring(newFile.Name.IndexOf(".") + 1); String type = mime.GetMimeTypeFromExtension(ext); Intent openFile = new Intent(Intent.ActionView, Android.Net.Uri.FromFile(newFile)); openFile.SetDataAndType(Android.Net.Uri.FromFile(newFile), type); openFile.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop | ActivityFlags.NewTask); PendingIntent p = PendingIntent.GetActivity(context, 0, openFile, 0); var notification = new Android.Support.V4.App.NotificationCompat.Builder(context) .SetSmallIcon(Android.Resource.Drawable.StatNotifySync) .SetContentTitle(FileName) .SetContentText(" Downloading") .SetOngoing(false); notification.SetProgress(0, 0, true); NotificationManager notificationmanager = (NotificationManager)Android.App.Application.Context.GetSystemService(Service.NotificationService); // Build Notification with Notification Manager notificationmanager.Notify((int)NotificationId, notification.Build()); webClient.DownloadDataCompleted += (s, e) => { try { if (!_appDirectory.Exists()) { _appDirectory.Mkdirs(); } var bytes = e.Result; // get the downloaded data { notification.SetContentText(" Downloaded"); notification.SetContentTitle(FileName); notification.SetContentIntent(p); notification.SetProgress(0, 0, false); notification.SetAutoCancel(true);// Notification.Flags = NotificationFlags.AutoCancel; //System.IO.File.WriteAllBytes(filePath, bytes); notificationmanager.Notify((int)NotificationId, notification.Build()); // writes to local storage } } catch (Exception ex) { } }; } catch (System.Exception ex) { } }