understanding the manual for google cast companion library - java

[SOLVED] I did not have the same namespace on both ends.
I have this manual page about the Google cast companion library and I don't understand the part about 'Support for data-centric applications' where it says
"This will send a message. Messages that are sent to the sender from the receiver can be
captured by extending DataCastConsumerImpl class and overriding the following callbacks:"
I have all the code for sending the message but when I press the 'confirmButton' nothing happens and the log doesn't throw any exceptions. So I wanted to add the 'onMessageSendFailed' callback but I have no idea how to add it to my code.
Thank you in advance for your help!
If you need more info I will be glad to give it!

First, what do you expect to happen when you send that message? Is your receiver registered to receive messages on that namespace? Is that not happening? You need to be more clear when you say "nothing happens". As for capturing onMessageSendFailed() callback, you need to either implement IDataCastConsumer or extend DataCastConsumerImpl and override the method(s) that you are interested in and then register your implementation with the DataCastManager instance:
mDataCastConsumerImpl = new DataCastConsumerImpl(){
public void onMessageSendFailed(Status status) {
// do as you want
}
....
}
...
mDataCastManager.addDataCastConsumer(mDataCastConsumerImpl);
...

Related

Closing an application programmatically with custom error message?

I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}

send message from android telegram source to to specific user id

I want to know, how can i send a message (for ex: text) from owner client to some body's id with coding(dynamically)in android telegram source?
what is that method?and objects?
if i want explain more i mean send message (to specific user id )from one of telegram source classes.
here is telegram source GitHub take look on it(the bad point is, it haven't any comment)
these classes may help to find it, but i cant figure it out
MessageObject.java
TLRPC.Message.java
ChatAttachAlert.java
SendMessagesHelper.java
ChatActivity.java
thanks.
you should use something like this method: SendMessagesHelper.getInstance().sendMessage(). note that it's a network call and you should call it in a thread other than ui thread.
simplest way to send a message is like calling:
SendMessagesHelper.getInstance().sendMessage("Hi there", to_user_id, null, null, false, null, null, null);
There are different types of messages and different ways to use this function. if you want to find out how to send other types of messages, search the java codes directory for "sendmessageshelper" and find how the sendMessage function is used in them.

check automatically for new message android

I am trying to create a simple android messaging app. So basically let us assume that user A sends a message to user B. I would like that user B receives a notification when the message is received. I know how to create the notification and all. But basically I would like to know how the user B constantly checks if a new message has been received even when he is out of the app, and then that would trigger the notification and subsequent actions.
Thank you
You have to setup an unbound background service.
With this you can constantly make pull-requests to your server or get push-notifications from your server and display notifications.
https://developer.android.com/training/run-background-service/create-service.html
You can use Event Bus lib for this purpose. When new message will be received it will create and event and then you can receive that event event and do other operations.
If you are talking about text messages then you will have to create a BroadcastReceiver
http://developer.android.com/reference/android/content/BroadcastReceiver.html
You can see my answer here for SMS Receiver
Verify sms text message by app before it displayed to user
Don't forget to give permissions in your app's manifest.
Hope it helps.

execute javascript code in an android.webkit.WebView without loadUrl or XHR

I am writing a phoneGap plugin to allow multitouch on android devices (hoping to get this included in phonegap/callback eventually)
Event delegation is taking ~200ms using the plugin success callback and ~50ms with the WebView.loadUrl('javascript:somecodehere()') call
Unfortunately loadUrl has the side-effect of flickering the soft keyboard which isn't acceptable for a general solution.
Phonegap's Plugin.success uses an internal web server and an XmlHttpRequest object to send data, this method is way too slow.
Is there any 3rd method of sending javascript to the web browser? (or even sending a poke to the javascript engine to cause an event to happen, so that event could check a custom jsInterface object)
Take a look at addJavascriptInterface in the WebView class. It sounds more like what you are looking for.
In you plugin try calling:
this.ctx.sendJavascript(statement);
Not quite as fast as loadUrl but it may be a bit faster than returning a PluginResult.
You could roll your own stripped down message queue with a java object that is basically an arraylist and an accessor, then use addJavascriptInterface to bind it into the javascript context and inject a javascript polling loop that uses setTimeout to call the accessor method of your queue. Whenever you have javascript to execute, just add it to your arraylist. I'm not sure how it would perform, but perhaps it's worth a try?
class JSQueue {
private ArrayList<String> messages;
public String getMessage() {
String message = "";
if(messages.size() >0) {
message = messages.remove(0);
}
return message;
}
public void addMessage(String message) {
messages.add(message);
}
}
JSQueue jsq = new JSQueue();
dc.appMobiCanvas.hiddenView.addJavascriptInterface(jsq, "jsq");
dc.appMobiCanvas.hiddenView.loadUrl("javascript:(function checkJSQ(){eval(jsq.getMessage());setTimeout(checkJSQ, 50);}})();");
//add messages via jsq.addMessage();
It seems we have developed something similar
https://github.com/Philzen/webview-multitouch-polyfill
However, i have never experienced the issue you're describing before, but maybe you would like to test on your device or maybe contribute your expertise to the project. It has already been suggested on the Cordova (Phonegap) Roadmap, so we'll happy about every user and/or contributor to help this cause!

Add messages with Spring

I have seen that I can add errors and render them via <form:errors /> tag and addError() method of BindingResult class, but I wonder if there is something similar to send information messages to the JSP.
I mean, I want to add messages when the operation has been successful. I know I could do it by sending an error, but it would make no sense to me to add errors when there haven't been any error at all.
Why don't you just add the messages as properties of the model that is passed to the view. In your JSP you would check to see if they are not null, and if not, display them.
Interesting. I found this in an old project of mine.:
(this was a base controller, but could well be an utility method)
protected void addMessage(String key, boolean isError,
HttpServletRequest request, Object... args) {
List<Message> msgs = (List<Message>) request.getAttribute(MESSAGES_KEY);
if (msgs == null) {
msgs = new LinkedList<Message>();
}
Message msg = new Message();
msg.setMessage(msg(key, args));
msg.setError(isError);
msgs.add(msg);
request.setAttribute(MESSAGES_KEY, msgs);
}
and then in a messages.jsp which was included in all pages I had:
<c:forEach items="${messages}" var="message">
//display messages here
</c:forEach>
MESSAGES_KEY is a constant of mine with a value "messages" (so that it is later accessible in the forEach loop).
The Message class is a simple POJO with those two properties. I used it for info messages as well as for custom non-validation errors.
This is a rather custom solution, but perhaps I hadn't found a built-in solution then. Google a bit more before using such a solution.
Use something like Flash messages in Rails.
The hard part is to keep the message in a redirect after post. I.e. you submit a form and you redirect to another page that shows a message notifying you that you have succeded in your action.
It is obvious that you can't keep the message in the request because it will be lost after the redirect.
My solution consists in keeping a session scoped bean that contains the message text and its type (notice, warning or error). The first time you read it in a JSP you have to clear it to avoid showing it more than once.

Categories

Resources