0

I have been searching about it but I did not get any useful information.

  • I am trying to develop an android application. In this application I will create trip as an admin user. I will have huge client user and I want to send them notification about my created trip.
  • User will choose a specific time to see the notification.I want to show the notification on specified time though users are offline that time.
  • Notification will get data from SQLite from my phone Database.

I don't know how to do that. I have googled a lot but don't get any idea or solution.

If do you have any suggestion please help me out, please suggest me any link or other tutorial etc,

Thanks in advance.

Tabish khan
  • 772
  • 8
  • 11
  • Push notifications are based on **socket connections** with GCM of FCM hence you cannot send a Push notification when the user is offline. Can you explain your use case so that anyone can suggest some other way maybe? – Zohair Nov 21 '17 at 06:50
  • 1
    Local push u can do it right, like an alarm or scheduled notifications it will show in notification bar without any internet that data will fetch from DB.You can use Notification manager for push notification & you cannot send to other devices without Internet – Hanuman Nov 21 '17 at 06:50
  • i am creating application based on daily notification, here i set some notifications into Sq-lite and i have to send that notification to the user daily at morning 8.00am @ Zohair – Tabish khan Nov 21 '17 at 06:54
  • Yes you can partially send push notification offline. But it depend on your requirement . Is it all things in locally? –  Nov 21 '17 at 06:56
  • What is your scenario? –  Nov 21 '17 at 06:58
  • @Hanuman you mean i cannot send that notification to my users or we can say other devices ? – Tabish khan Nov 21 '17 at 06:59
  • @EnamulHaque my scenario is i have saved some tips into Sq-lite and i want to send that tips to my users, my user should get that tips as an notification to there cell phone on daily bases if they are also offline. – Tabish khan Nov 21 '17 at 07:03
  • Nope, offline then can't receive if you send also, scheduling notifications you can send as you mentioned in last comment info – Hanuman Nov 21 '17 at 07:03
  • every day morning 8.00 an make a scheduler after finising that scheduler create local notification, fetch data from db it will show in status bar as a notificaiton – Hanuman Nov 21 '17 at 07:04
  • No it is impossible according your scenario. If your have all user phone number. (suppose your collect them on registration time on your app) then you can send SMS and receive them in BroadcastReceiver in your app and format sms as notification. –  Nov 21 '17 at 07:10
  • @Hanuman 8.00am is a default time but user can set there own time when they want to get notification from my side – Tabish khan Nov 21 '17 at 07:10
  • that you can change right, when ever user changes you will get the changed time & pass to the scheduler right? – Hanuman Nov 21 '17 at 07:14
  • @EnamulHaque after clicking notification bar user should redirect to an activity for reading whole notification its not about message sir its all about notification – Tabish khan Nov 21 '17 at 07:15
  • Are you using FCM? –  Nov 21 '17 at 07:16
  • @Hanuman suppose 50 people are using my application so they should have right to set there own time to get notification – Tabish khan Nov 21 '17 at 07:17
  • @EnamulHaque No i am not using FCM or GCM i have to do these task without using internet – Tabish khan Nov 21 '17 at 07:19
  • Are you using any server? –  Nov 21 '17 at 07:20
  • @EnamulHaque yes my client has its own server – Tabish khan Nov 21 '17 at 07:22
  • yes, that's correct – Hanuman Nov 21 '17 at 07:23
  • So when you set some trip you can save them in server side database. Then, create a Service in you app to detect your user connect to internet. When user connect to the internet then send a server request and grab the trip information if any. Save them in his local storage. Then create another service to show the notification on configured time of user form saved notification though user is offline that time. –  Nov 21 '17 at 07:28
  • @EnamulHaque Now you got my point so sir do you have any link tutorial or anything about all of this that i can use to resolve this issue if yes please let me know – Tabish khan Nov 21 '17 at 07:36
  • Which server side language you are using? –  Nov 21 '17 at 08:51
  • @EnamulHaque Php laravel – Tabish khan Nov 21 '17 at 09:14
  • Did you complete your requirement.. –  Nov 21 '17 at 17:59

1 Answers1

2
  1. If you create any trip save that information on server side database.

  2. In your app you need a BroadcastReceiver to detect user is now connected with internet. Then create a server request and get trip information you have recently created as response. Internet Connection Detection code link

  3. Save the information that user device locally in SQLite database.

  4. Now you have to use AlarmManager to show the Notification in a specific time by default or as user setting time. Alarm Example

  5. You will show notification on the place of sound play in BroadcastReceiver.

  6. Notification Code.

    private void showNotification(Context context){
    
    //Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    //v.vibrate(500);
    
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    //Setting icon, title, message
    mBuilder.setSmallIcon(R.drawable.notification);
    mBuilder.setContentTitle("data form sqlite");
    mBuilder.setContentText("data form sqlite.");
    
    //Setting sound
    Uri alarmSound = Uri.fromFile(new File("file:///android_asset/noficicatin.mp3"));//RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(alarmSound);
    MediaPlayer mp = new MediaPlayer();
    try {
        mp.setDataSource(new File("file:///android_asset/noficicatin.mp3").getAbsolutePath());
        mp.start();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    //mBuilder.setAutoCancel(true);
    //Setting Vibratortion
    long[] pattern = {500,500,500,500,500,500,500,500};
    mBuilder.setVibrate(pattern);
    
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(notificationID, mBuilder.build());
    
    
    }
    

I hope you know show create server request, get response and SQLite database use. Best of luck.