0

I'm creating an app which collects a data and saves in a particular folder. Now I was looking for source code which will automatically uploads to Google drive of a given account(and not the user's managed account) when only WiFi is available. I can upload a file to Drive but I was specifically looking for this.

  • I'm a newbie so I have tried with https://github.com/googledrive/android-quickstart that too after a lot of trial and error I was able to succeed. – DroidSig May 05 '16 at 13:52
  • If you we wish to manage one single repository for all the users (as implied by your question) you probably don't want to use drive. Try firebase. – Anatoli May 05 '16 at 23:48

1 Answers1

0

Before uploading, check if WiFi is enabled:

 public static boolean isWiFiConnected() {
    WifiManager wifiMgr = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

    if (wifiMgr != null && wifiMgr.isWifiEnabled()) { // Wi-Fi adapter is ON

        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();

        if (wifiInfo != null && wifiInfo.getNetworkId() == -1) {
            return false; // Not connected to an access point
        }
        return true; // Connected to an access point

    } else {
        return false; // Wi-Fi adapter is OFF
    }
}

don't forget about permission:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
Choletski
  • 7,074
  • 6
  • 43
  • 64