Here is code how i have implemented calling.
#Override
public void onClientStarted(SinchClient sinchClient) {
Log.e(TAG, "started");
callClient = sinchClient.getCallClient();
callClient.addCallClientListener(this);
}
public void initiateCall(String receiverId) {
Call call = callClient.callUserVideo(receiverId);
call.addCallListener(this);
}
But i want to pass some data like username, profile image and other things, does there any way to pass those data with video calling?
Got solution from sinch developer.
You can pass along custom data providing headers to the
callUserVideo(String toUserId, Map headers) method. The headers you
pass can be retrieved from the incoming Call object using getHeaders()
method.
https://download.sinch.com/docs/android/latest/reference/com/sinch/android/rtc/calling/Call.html
We can pass extra values in map when initializing call.
HashMap<String,String> map=new HashMap<>();
map.put("userId","5");
map.put("profileImage","image url");
Call call = callClient.callUserVideo(receiverId,map);
Related
Assuming i have this dummy API
#POST("somepath/setSomething")
Call<ExecuteResponse> setSomething(#Body ExecuteInput input);
and this callBack
Callback<ExecuteResponse> callBack = new Callback<ExecuteResponse>() {
#Override
public void onResponse(Call<ExecuteResponse> call, Response<ExecuteResponse> response) {};
How can i access the body of the call and getting back my ExecuteInput Object?
You can do response.getBody() and you will get the object you specified inside Response<???>. In this case, ExecuteResponse.
Of course, I'm supposing you have defined the #SerializedName inside your object or that you have the right field names inside the ExecuteResponse model class.
I'm trying to use retrofit for get records from my API and it works fine when i do something like this.
public interface materialAPI {
#GET("/mlearningServices/Course")
public void getMaterials(Callback<List<materialClass>> response); } public void getMaterials()
{
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(Root_Url).build();
Log.i(TAG , "hERE IS THE LINK"+adapter.toString());
materialAPI api = adapter.create(materialAPI.class);
api.getMaterials(new Callback <List<materialClass>>() {
#Override
public void success(List<materialClass> list, Response response) {
materials = list;
showList();
customAdapter customAdapter = new customAdapter();
listView.setAdapter(customAdapter);
}
#Override
public void failure(RetrofitError error) {
}
});
}
The above code works fine and i can get all my materials but what i want to achieve next is get material with any id . When a user selects a paticular material, i want to pass the id into the get url so i can get the records
meaning i have to do something like this
#GET("/mlearningServices/Course/{myId}")
..
How to i add myId to the callback method. This is my first time of using retrofit
Use the #Path annotation
#POST("/mlearningServices/Course/{myId}")
public void getMaterials(#Path("myId") String id, Callback<Response> response);
References:
https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Path.html
http://square.github.io/retrofit/
That you are asking about is called a path variable. To set one, you must rewrite your method signature as this:
public void getMaterials(#Path("myId") String id, Callback<List<materialClass>> response);
This way, the variable defined as /path/to/your/endpoint/{nameOfPathVariable} will be injected into that String parameter passed to the method. You could also define it as an Integer, and retrofit will try to cast it accordingly.
Solution:
You can use this to pass your id, Use the #Path annotation
#GET("/mlearningServices/Course/{myId}")
Call<materialClass> getMaterials(#Path("myId") String id);
#Path is some data that you wish to provide it to GET method before Question Mark ("?") and #Query("..") is some data you wish to provide after "?"
Hope you have understood.
Is it possible to write a cloud code function directly into android studio? If not where could I write one? I can't find it on my parse dashboard
thanks
Cloud code is only written in the express module of your app inside cloud/main.js file, you can create cloud functions there and call them from your android app.
Example:
Parse.Cloud.define("getPosts", function(request, response){
var query = new Parse.Query("Posts");
//TODO: query constraints here
query.equalTo("key",request.params.text);
query.find().then(function(results){
response.success(results);
});
});
and you can call this function from android as below:
public static void getPosts(String text, final onSearch onSearch) {
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("text", text);
ParseCloud.callFunctionInBackground("getPosts", hashMap, new
FunctionCallback<List<Post>>() {
#Override
public void done(List<Post> object, ParseException e) {
//TODO: use search results...
}
});
}
you can see other cloud functions and parameters in the docs: Cloud Code Guide
In my andorid app I am making a GET request using Retrofit2:
http://myapi.com/items/list
But I would also like to make another request e.g.
http://myapi.com/items/list/filter/active:true,min_price:100
So the filter parameter is optional. I am trying to do the following:
#GET("items/items/list{filter}")
Observable<ResponseItems> getItems(#Path("filter") String filter);
and calling it like:
service.getItems("")
and:
service.getItems("/filter/active:true,min_price:100")
But it does not work. So I ended up creating two separate service calls, one with filter param and other without. I think that there should be more elegant method though.
So i've seen what you are trying to achieve.
How your api declaration should looks like:
#GET("items/list/{filter}")
Observable<ResponseItems> getItems(#Path(value = "filter", encoded = true) String filter);
and a call service.getItems("") would lead to http://myapi.com/items/list/ be called
a call service.getItems("filter/active:true,min_price:100") would lead to
http://myapi.com/items/list/filter/active:true,min_price:100 be called.
An encoded property in #Path annotation is set because your optional path parameter contains / and retrofit encodes it without that property.
So as i wrote in comments better use two declarations:
#GET("items/list/")
Observable<ResponseItems> getItems();
#GET("items/list/filter/{filter}")
Observable<ResponseItems> getItems(#Path(value = "filter") String filter);
so you may call it like service.getItems("active:true,min_price:100")
In simple word make method over loading. Create two method with same name and different parameter. Check my below source code. (written in kotlin)
#GET("myportal/news/{id}")
fun getNewsList(#Path("id") id: String): Call<NewsEntity>
#GET("myportal/news/{id}/{dateTime}")
fun getNewsList(#Path("id") id: Long, #Path("dateTime") dateTime: String): Call<NewsEntity>
Its better to use HashMap to send optional params in a request, this allows you to send single/multiple optional params in your request also if you send the HashMap empty it will not affect your request.
Your interface will contain code like snippet below
#POST("yourUrl")
#FormUrlEncoded
Call<YourResponse> yourApiRequest(#Header("Authorization") String token,
#Field("mandatoryParam") int mandatoryParam,
#FieldMap Map<String, String> optionalParamMap);
And your API call will be something like the following
private HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("optionalParam1", value1);
hashMap.put("optionalParam2", value2);
ApiClient.getApiClient().getApiInterface().yourApiRequest(token,
mandatoryParam, hashMap)
.enqueue(new Callback<YourResponse>() {
#Override
public void onResponse(Call<YourResponse> call, Response<YourResponse> response) {
}
#Override
public void onFailure(Call<YourResponse> call, Throwable t) {
}
});
In a case where you don't want to send any optional params you can pass an empty hashmap to your request.
I am required to pass cookie value in my next service after log in I am using volley library to call services. I have successfully saved cookie using this it successfully saves ids in preference.
i have use getHeader for next request
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
return myApp.getSessionCookie();
}
but for my next request how to use this value?