-2

When internet connection is on I want to send location parameter to server, and when internet off I want to save location parameter in realm database and after sometime when internet again on I want to send current location parameter to server and also send location parameter which saved in realm database to server which approach should I used.

Payal Sorathiya
  • 756
  • 1
  • 8
  • 23
Fahad Aziz
  • 9
  • 1
  • 6

2 Answers2

0

You can create a database and store those values there. Now after sending those value you must remove them from you database.

Now , create a broadcast class that always check the network status.When network comes it will check that db and send them on server. You can code it accordingly.

public class NetworkStatusChangeReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    boolean status = Utility.isInternetAvailable(context);
    if (!status)
    {
        Toast.makeText(context, "Network Error !", Toast.LENGTH_SHORT).show();
    }
 }
}

Put this in manifest.

   <receiver    
        android:name="NetworkStatusChangeReceiver"
        android:label="NetworkStatusChangeReceiver" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
        </intent-filter>
    </receiver>

This might be helpful !!!!!

Dilip
  • 2,622
  • 1
  • 20
  • 27
0

Follow this link to check internet connection check network connection

and if internet connection not found then store it to local database.

Aj 27
  • 2,316
  • 21
  • 29