简体   繁体   中英

How to send push notifications using java smack library + openfire server on web app,Android,IOS

我已经设置了openfire服务器,并希望通过Java后端服务器在webapp,Andriod和ios上发送推送通知。即,如果我通过java在openfire上发送推送通知消息,则它应该能够在连接的应用程序上发送通知。

As far as I know, there is no plugin for Openfire that support Push notification like Firebase.

The solution for your problem could be the Background service. This service will be running in the background and receiving stanza for your application. Also downside of this solution would be battery life as your service is constantly running in background.

Your service could be started with app and also could be started with receivers like BootReceiver, NetworkReceiver, ShutdownReceiver etc.

public class MessageService extends Service { }

And in lets say NetworkReceiver start your service that process Stanza like Message or PResence packets:

public class NetworkReceiver extends BroadcastReceiver {
    public static final String EXTRA_DATA_NAME_NETWORK_CONNECTED = "my.package.name.NetworkConnected";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
            Intent serviceIntent = new Intent(MessageService.ACTION_NETWORK_STATUS, null, context, MessageService.class);
            serviceIntent.putExtra(EXTRA_DATA_NAME_NETWORK_CONNECTED, NetworkUtils.isNetworkConnected(context));
            context.startService(serviceIntent);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM