lundi 29 février 2016

Push Notifications - Android

I am working on a small project that involves a web interface that can send information to my android app which will display such information as Push Notifications.

But here is the thing, I am a bit confused with how to do that. As in what step will i have to take.

So I have a web interface in HTML which has a Textfield for notification Title, Content, and a submit button. I want it that when the user clicks the Submit button, the webpage will send the text that s in the Title and Content fields to my android app and then the app will just display them as push notifications.

So far on the app i have it that when you click a button on your device then it just shows a notification on the Actionbar. This is great for testing but It would be better that you can just compose your notification through a web interface.

My test Push Notification code for the app:

button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent();
                PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

                // TODO: Make this accessible to exterior projects, such as web interface.
                Notification notification = new Notification.Builder(MainActivity.this)
                        .setTicker("Notification")
                        .setContentTitle("Important Message")
                        .setContentText("This is an example of a push notification using a Navigation Manager")
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentIntent(pIntent)
                        .build();

                notification.flags = Notification.FLAG_AUTO_CANCEL;

                NotificationManager nManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

                nManager.notify(0, notification);
            }
        });

If anyone could be so kind to give me a hand, it would be much appreciated.




Aucun commentaire:

Enregistrer un commentaire