Support
Quality
Security
License
Reuse
kandi has reviewed AndroidAsync and discovered the below as its top functions. This is intended to give you an instant insight into AndroidAsync implemented functionality, and help decide if they suit your requirements.
Based on NIO. Single threaded and callback driven.
All operations return a Future that can be cancelled
Socket client + socket server
HTTP client + server
WebSocket client + server
Download
<dependency>
<groupId>com.koushikdutta.async</groupId>
<artifactId>androidasync</artifactId>
<version>(insert latest version)</version>
</dependency>
Download a url to a String
// url is the URL to download.
AsyncHttpClient.getDefaultInstance().getString(url, new AsyncHttpClient.StringCallback() {
// Callback is invoked with any exceptions/errors, and the result, if available.
@Override
public void onCompleted(Exception e, AsyncHttpResponse response, String result) {
if (e != null) {
e.printStackTrace();
return;
}
System.out.println("I got a string: " + result);
}
});
Download JSON from a url
// url is the URL to download.
AsyncHttpClient.getDefaultInstance().getJSONObject(url, new AsyncHttpClient.JSONObjectCallback() {
// Callback is invoked with any exceptions/errors, and the result, if available.
@Override
public void onCompleted(Exception e, AsyncHttpResponse response, JSONObject result) {
if (e != null) {
e.printStackTrace();
return;
}
System.out.println("I got a JSONObject: " + result);
}
});
Download a url to a file
AsyncHttpClient.getDefaultInstance().getFile(url, filename, new AsyncHttpClient.FileCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse response, File result) {
if (e != null) {
e.printStackTrace();
return;
}
System.out.println("my file is available at: " + result.getAbsolutePath());
}
});
Caching is supported too
// arguments are the http client, the directory to store cache files,
// and the size of the cache in bytes
ResponseCacheMiddleware.addCache(AsyncHttpClient.getDefaultInstance(),
getFileStreamPath("asynccache"),
1024 * 1024 * 10);
Need to do multipart/form-data uploads? That works too.
AsyncHttpPost post = new AsyncHttpPost("http://myservercom/postform.html");
MultipartFormDataBody body = new MultipartFormDataBody();
body.addFilePart("my-file", new File("/path/to/file.txt");
body.addStringPart("foo", "bar");
post.setBody(body);
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback(){
@Override
public void onCompleted(Exception ex, AsyncHttpResponse source, String result) {
if (ex != null) {
ex.printStackTrace();
return;
}
System.out.println("Server says: " + result);
}
});
Can also create web sockets:
AsyncHttpClient.getDefaultInstance().websocket(get, "my-protocol", new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
if (ex != null) {
ex.printStackTrace();
return;
}
webSocket.send("a string");
webSocket.send(new byte[10]);
webSocket.setStringCallback(new StringCallback() {
public void onStringAvailable(String s) {
System.out.println("I got a string: " + s);
}
});
webSocket.setDataCallback(new DataCallback() {
public void onDataAvailable(DataEmitter emitter, ByteBufferList byteBufferList) {
System.out.println("I got some bytes!");
// note that this data has been read
byteBufferList.recycle();
}
});
}
});
AndroidAsync also let's you create simple HTTP servers:
AsyncHttpServer server = new AsyncHttpServer();
List<WebSocket> _sockets = new ArrayList<WebSocket>();
server.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("Hello!!!");
}
});
// listen on port 5000
server.listen(5000);
// browsing http://localhost:5000 will return Hello!!!
And WebSocket Servers:
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listen(AsyncServer.getDefault(), port);
httpServer.websocket("/live", new AsyncHttpServer.WebSocketRequestCallback() {
@Override
public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {
_sockets.add(webSocket);
//Use this to clean up any references to your websocket
webSocket.setClosedCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
try {
if (ex != null)
Log.e("WebSocket", "An error occurred", ex);
} finally {
_sockets.remove(webSocket);
}
}
});
webSocket.setStringCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
if ("Hello Server".equals(s))
webSocket.send("Welcome Client!");
}
});
}
});
//..Sometime later, broadcast!
for (WebSocket socket : _sockets)
socket.send("Fireball!");
Futures
Future<String> string = client.getString("http://foo.com/hello.txt");
// this will block, and may also throw if there was an error!
String value = string.get();
when I add viewbinding in gradle in android studio it comes an error
buildFeatures{
dataBinding = true
viewBinding = true
}
-----------------------
buildFeatures {
viewBinding true
}
-----------------------
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
android {
//...
buildFeatures {
viewBinding true
}
}
android{
//....
viewBinding {
enabled = true
}
}
-----------------------
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
android {
//...
buildFeatures {
viewBinding true
}
}
android{
//....
viewBinding {
enabled = true
}
}
-----------------------
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
android {
//...
buildFeatures {
viewBinding true
}
}
android{
//....
viewBinding {
enabled = true
}
}
QUESTION
when I add viewbinding in gradle in android studio it comes an error
Asked 2020-Jul-18 at 10:24I am using android studio version 4.0.1.
when I add viewbinding it comes an error .
Error when I add viewbinding in gradle.
buildFeatures {
viewBinding = true
}
build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "1.2.0"
resValue("string", "growingio_project_id", "8979dc98cc52320f")
resValue("string", "growingio_url_scheme", "growing.1f3e3791e1d6aee5")
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibilityVersion
targetCompatibility rootProject.ext.targetCompatibilityVersion
}
buildFeatures {
viewBinding = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: "*.jar")
implementation deps.swipeRevealLayout
implementation deps.glide
implementation deps.growingio
implementation(deps.rxbus) {
exclude group: 'com.jakewharton.timber', module: 'timber'
}
implementation deps.androidasync
implementation deps.timber
}
Error :
Could not find method buildFeatures() for arguments [build_6zjavhoqnf2k7dfs2qrq542f3$_run_closure1$_closure5@6cd00094] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
Why this error comes ?
How can I solve this error?
ANSWER
Answered 2020-Jul-17 at 10:44try to add "dataBinding = true" and sync the project
buildFeatures{
dataBinding = true
viewBinding = true
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit