mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-16 13:47:47 +01:00
Adding internet connectivity with 'http' Gadgetbridge event
FIXME - still needs a setting to enable that is off by default
This commit is contained in:
parent
2a53219a14
commit
c597adf27f
@ -213,6 +213,7 @@ dependencies {
|
|||||||
implementation 'com.github.wax911:android-emojify:0.1.7'
|
implementation 'com.github.wax911:android-emojify:0.1.7'
|
||||||
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
|
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
|
||||||
implementation "androidx.multidex:multidex:2.0.1"
|
implementation "androidx.multidex:multidex:2.0.1"
|
||||||
|
implementation 'com.android.volley:volley:1.2.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
||||||
|
5
app/src/banglejs/AndroidManifest.xml
Normal file
5
app/src/banglejs/AndroidManifest.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
</manifest>
|
@ -65,6 +65,7 @@ import java.util.Set;
|
|||||||
import de.cketti.library.changelog.ChangeLog;
|
import de.cketti.library.changelog.ChangeLog;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2;
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
@ -438,6 +439,12 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BuildConfig.INTERNET_ACCESS) {
|
||||||
|
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) {
|
||||||
|
wantedPermissions.add(Manifest.permission.INTERNET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!wantedPermissions.isEmpty()) {
|
if (!wantedPermissions.isEmpty()) {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
// If this is not the first run, we can rely on
|
// If this is not the first run, we can rely on
|
||||||
|
@ -31,6 +31,13 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
import com.android.volley.Request;
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.RequestQueue;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
import com.android.volley.toolbox.Volley;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -267,6 +274,39 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case "http": {
|
||||||
|
// FIXME: This should be behind a default-off option in Gadgetbridge settings
|
||||||
|
RequestQueue queue = Volley.newRequestQueue(getContext());
|
||||||
|
String url = json.getString("url");
|
||||||
|
// Request a string response from the provided URL.
|
||||||
|
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
||||||
|
new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
try {
|
||||||
|
o.put("t", "http");
|
||||||
|
o.put("resp", response);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
|
uartTxJSON("http", o);
|
||||||
|
}
|
||||||
|
}, new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
try {
|
||||||
|
o.put("t", "http");
|
||||||
|
o.put("err", error.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
|
uartTxJSON("http", o);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
queue.add(stringRequest);
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user