JibinNajeeb
JibinNajeeb

Reputation: 834

In my application trying to get notification whenver db in webserver updates. How this can be achieved?

Im using Jersey Rest service for my local web server. This is used for user login and registering from android. I also trying to achieve when ever a new user is added the admin should get a notification. How this can be achieved? I recently came to know about Jersey Sse. Is it achievable through Jersey SSe. Please help me find a easy sample/document.

Upvotes: 0

Views: 27

Answers (1)

W4R10CK
W4R10CK

Reputation: 5550

Every time a new user is registered, which means a new ID is made in the DB of the User. Run a Android Service for Admin, which will call a Server Script to check if new ID is available or not. If new ID found for the User deploy a notification to Admin.

Dummy Code [Change as per yours]

public class your_service extends Service {


public your_service() {
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final Handler handler = new Handler();

    handler.postDelayed(new Runnable() {
    public void run() {
    request = new StringRequest(Request.Method.POST, your_url, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
       // add code, ur logic
       //notify here
       //                         
     }
    }, 
       new Response.ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) 
             {//empty
             }
          });

        Volley.newRequestQueue(getBaseContext()).add(request);
        handler.postDelayed(this, 60000); //repeat this code every 1 minutes
             }
          }, 1000); // first wait for 1 seconds
        }
       }
    };
    return START_STICKY;
}
}

Upvotes: 1

Related Questions