I'm using ktor for create rest api with kotlin but when i change api and run again response won't change.
This is my code
fun main(args: Array<String>) {
embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("Hi", ContentType.Text.Plain)
}
}
}.start(wait = true)
}
When run it for the first time work correct and show in localhost:8080
Hi
But if i change
call.respondText("Hi", ContentType.Text.Plain)
to
call.respondText("Hello", ContentType.Text.Plain)
And run it again response no change and steel show Hi in localhost:8080
Update
If i close android studio and open it again and run its work and show Hello but again if i change anything nothing will be change
i don't have any idea to why this is happening.
It happens with me when android instant run feature is enabled.
Please consider to disable it and try again.
Related
I am relatively new to MQTT and am trying to connect via a websocket in my Android app.
HiveMQ and Paho seem to be the most commonly used libraries, so I'll try my luck with those for now.
Unfortunately I got right at the first library and would need a hint on how to proceed, as the docs don't say anything about this unfortunately.
With HiveMQ, it's not entirely clear to me how to connect via websocket, and how to customize my credentials/headers, because I need to add some custom header like "x-amz-customauthorizer-name" and some more.
This is my attempt without adding the user credentials:
val client = Mqtt3Client.builder()
.identifier(UUID.randomUUID().toString())
.serverAddress(InetSocketAddress(result.data.webSocketServer, 443))
.sslWithDefaultConfig()
.addConnectedListener { context: MqttClientConnectedContext? -> Log.e(javaClass.simpleName, "mqtt Here Connected Yay") }
.addDisconnectedListener { context: MqttClientDisconnectedContext -> Log.e(javaClass.simpleName, "mqtt Disconnected: " + context.cause.message!!) }
.buildAsync()
client.connect()
you just need to add the webSocketConfig to the builder, something like this:
Mqtt3Client client = Mqtt3Client.builder()
.identifier(UUID.randomUUID().toString())
.serverAddress(new InetSocketAddress("localhost", 443))
.sslWithDefaultConfig()
this line-> .webSocketConfig(MqttWebSocketConfig.builder().subprotocol("mqtt").serverPath("/mqtt").build())
.buildAsync();
But I'm think you can't add custom headers yet, see https://github.com/hivemq/hivemq-mqtt-client/issues/457.
Greetings,
Michael
There is a simple app in android studio written in kotlin.This is the following code in onCreate
val manager = FakeReviewManager(baseContext)
val request = manager.requestReviewFlow()
request.addOnCompleteListener{ request ->
if (request.isSuccessful){
Log.i("message","Rating")
manager.launchReviewFlow(this, request.result).addOnCompleteListener{
Log.i("message","Rating1")
}
}else{
}
}
In Logcat Messages showed successfully. But nothing has showed.How can Fix this this problem?
FakeReviewManager is strictly used for unit test and does not show any UI, if a UI is what you are expecting.
I am trying to make an android app connecting to api, and for that I am using Kotlin Coroutines and Retrofit. I was following this tutorial (https://android.jlelse.eu/android-networking-in-2019-retrofit-with-kotlins-coroutines-aefe82c4d777) trying to setup my own api, but I stumbled on a problem. I can't get any data from api because I can't process response.
I don't know much about coroutines, so I don't understand whats the problem here. If I run debug and go line by line it is working perfectly each time, but if I run the app, it only prints TestPoint1. Also it doesn't throw any error and response is always 200 OK. I have tried to combine
val standings = service.getStandings()
and
val response = standings.await()
into one line, after which it doesn't work on debug either. It continues on code after launched coroutine.
val service = ApiFactory.footballApi
GlobalScope.launch(Dispatchers.Main) {
val standings = service.getStandings()
try {
Log.d("TAG", "TestPoint1")
val response = standings.await()
Log.d("TAG", "TestPoint2")
if(response.isSuccessful){
//store data
}else{
Log.d("MainActivity ",response.errorBody().toString())
}
}catch (e: Exception){
Log.d("TAG", "Error")
}
}
Switch the Dispatchers.Main to Dispatchers.IO . You can't make that request on the main thread .
The coroutines require a coroutine context in order to know in what thread they are going to run . For that , the Dispatchers class offer you some options . Currently you are making the request in the Dispatchers.Main which you cannot do because fetching data from the API , requires another thread . IO is the right thread for network calls .
Note :
Also please check : Internet permission, Internet connection .
I'm building a Cordova Ionic application which fetches JSON response on button click and display it. It's working fine in browser but it's not displaying anything in android.
angular.module('starter', ['ionic'])
.config(function($ionicConfigProvider) {
$ionicConfigProvider.navBar.alignTitle('center'); //align title in center
})
.controller('ControllerOne',[ '$scope', 'freshlyPressed', Ctrl])
.service('freshlyPressed', ['$http','$log', freshlyPressed]);
function Ctrl($scope, freshlyPressed){
$scope.refreshClicked = function(){
freshlyPressed.getBlogs($scope);
}
};
function freshlyPressed($http,$log){
this.getBlogs = function($scope){
$http.jsonp("https://public-api.wordpress.com/rest/v1.1/freshly-pressed?callback=JSON_CALLBACK")
.success(function(result, posts){
$scope.posts = result.posts;
});
};
};
How would I know if any exception occurred while testing the app in android?
[Edit] I'm new to Android & Cordova.
The only way you can find out if something goes wrong is if you add a .error function after the .success function, otherwise errors will not be caught.
Here is a code example for your current situation:
function freshlyPressed($http,$log){
this.getBlogs = function($scope){
$http.jsonp("https://public-api.wordpress.com/rest/v1.1/freshly-pressed?callback=JSON_CALLBACK")
.success(function(result, posts){
$scope.posts = result.posts;
})
.error(function(error){
console.log(error);
});
};
};
Although, I would highly recommend you switch to the .then() function, as .error and .success have been deprecated as described here.
You can debug your android apps with Chrome using DevTool.
To enable Remote Debugging follow these Remote Debugging Devices Documetation
.
To use it follow Chrome Inspector (Ionic Docs).
Hope this may help you.
I meet problem in JSONStore init function in Android. It will hang for about 10 minutes until then the JSONStore gives me the init result callback. This did occur only in Android and iPhone works fine. I can give the reproduce procedure:
Install my app in a 'clean' Android, which has not install the app before.
Successfully init the JSONStore by my arguemnts (I will attach the code below).
Then I re-install my app, note that I did't uninstall it but just replace it with a new build.
After replace I'm using the same auth try to init JSONStore, but it hangs....(Maybe will give the result callback at 10 minutes or longer, no error handlers trigger).
If a kill the app and re-launch it, then this time the JSONStore init very fast and works fine
I debug the App with inspect and I'm sure this is the problem that WL.JSONStore.init didn't give me result callback that hangs app. I don't know the reason why the first time need to consume so much time. Anyone meet the same issue as me?
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
console.info("init json store successfully!");
return true;
}).fail(function (errorObject) {
console.info("init json store failed!" + errorObject);
return false;
});
return promise;
I just tried out the following code in the same 6.1 build that you have, and it is working fine for me on both the Android Emulator and a Nexus 4:
var data_collection = {people : {
searchFields : {name : 'string', age : 'integer'}
}
};
var pscd = "samplepassword";
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
alert("init json store successfully!");
return true;
}).fail(function (errorObject) {
alert("init json store failed!" + errorObject);
return false;
});
return promise;
The only thing that might be different to your code is what your password or your data_collection variables are. Could you add more details regarding what data_collection is?