I want to develop a messaging app which will show messages from native content provider (sms uri ) and messages that has been sent from my app.
I am stuck while managing this messages.I have tried below idea but plese do suggest which is the best .
Here is the observer code I have used:
public class MyObserver extends ContentObserver {
public MyObserver(Handler handler) {
super(handler);
}
#Override
public void onChange(boolean selfChange) {
Log.e("uri","change");
this.onChange(selfChange, null);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
// do s.th.
// depending on the handler you might be on the UI
// thread, so be cautious!
Log.e("uri",""+uri.toString());
}
}
Uri uri = Uri.parse("content://sms/");
getContentResolver().registerContentObserver(uri,true,new MyObserver(new Handler()));
1.I have saved all native and A2A messages in databases so it was easy to show but I got problem while synching native message gets delete as there is not broadcast listener for message deletion.
2.Second option is two save only a2a message in database but it is complex to and time consuming to get messages from two different places (database and content provider and manage the to show view like inbox)
3.Third is to save all app to app messages in content provider with custom message type.and show all messages from content provider only .
Please guide me on this.
Related
I'm building android application with push notifications using Backendless as backend. I encountered a problem with handling buttons. I know that I can push notification with template(from Backendless Console) and there is an option to handle clicks, but I wonder if there is an option to do it all in code, not with template?
I have also searched for similar questions but everything I found was old and deprecated.
I use this function to push notification but I don't know how to set buttons and how to handle button clicks.
public static void sendPushNotification(String channel, String message, String header,
List<String> devices) {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushSinglecast(devices);
PublishOptions publishOptions = new PublishOptions();
publishOptions.putHeader("android-ticker-text", header);
publishOptions.putHeader("android-content-title", header);
publishOptions.putHeader("android-content-text", message);
Backendless.Messaging.publish(channel, message, publishOptions, deliveryOptions,
new AsyncCallback<MessageStatus>() {
#Override
public void handleResponse(MessageStatus response) {
}
#Override
public void handleFault(BackendlessFault fault) {
}
});
}
Solution :
https://support.backendless.com/t/customise-push-notification/10863/20
I finally found answer, if you had similar problem please go here and check:
https://support.backendless.com/t/customise-push-notification/10863/20
In Backendless, there is a method from which I can subscribe to a channel and listen for incoming messages.
Backendless.Messaging.subscribe(
channelName, //some random name
500, //500 ms interval for polling
new AsyncCallback<List<com.backendless.messaging.Message>>() {
#Override
public void handleResponse(List<com.backendless.messaging.Message> messages) {
System.out.println("message received on your channel");
}
#Override
public void handleFault(BackendlessFault backendlessFault) {
}
},
new AsyncCallback<Subscription>() {
#Override
public void handleResponse(Subscription subscription) {
System.out.println("You subscribed to channel" + subscription.getChannelName() + " succssesfuly");
}
#Override
public void handleFault(BackendlessFault backendlessFault) {
System.out.println("Error: " + backendlessFault.getMessage());
}
}
);
If it subscribes from the MainActivity, and data was sent while the app is in another Activity, how can it grab the data from the response (the List in the first handleResponse method) and use it in other activities?
Should I use a service? Should I bind activities to this service with the listener?
Or is there any less complicated way to accomplish my need?
In the very near future i want this listener to work when the app is in the background and show a notification to a user.
Backendless uses two types of Messaging, see Publish-Subscribe Messaging & Push Notifications. The first one is implemented using the listener you used above. The second one uses a service. please refer to the docs, although they are not very good at all they do provide the necessary information.
I'm making a GWT application that requires users to log in. If username and password are correct, then they are allowed to use the application.
What needs to be implemented in the onSuccess() method to make this possible ?
Thanks in advance.
DBConnectionAsync rpcService = (DBConnectionAsync) GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpcService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
target.setServiceEntryPoint(moduleRelativeURL);
rpcService.authenticateUser("admin", "admin", new AsyncCallback<User>() {
#Override
public void onSuccess(User result) {
// What to do here to open or redirect the user to a new page ?
}
#Override
public void onFailure(Throwable caught) {
// Failure
}
});
A simple way of doing this would be to fire an event to the eventbus of you application and then catch this event in the main controller of your application, which would trigger the opening of the right page.
This two pages should explain everything you possibly need to know to do this:
Everything about the architecture GWT MVP
Everything about activity and places (navigation and history)
Just as if you need more information.
From onSuccess you can call a method which will be defined in a corresponding presenter and from that method you can fire an event which will allow user to enter into your application only on successful authentication .
I'm trying to implement Server-sent events in the Play 2 framework (version 2.3.9) using Java. I'd like for an event to be sent to the client every time a "Message" entity is saved to the database. The entity should be sent to the client in Json format.
Message message = new Message();
//some code to populate bean here
message.save(); //save to db
//What do I do with message here?
I was thinking of making a service class that will send events.
public class SSEService {
public static void sendEvent(String data, String id, String name){
EventSource eventSource = new EventSource() {
#Override
public void onConnected() {
//no idea what to do here
}
};
EventSource.Event event = new EventSource.Event(data, id, name);
eventSource.send(event);
}
}
I would then call SSEService.sendEvent() after saving the message. Am I on the right track? What does data, id, and name correspond to in the Event constructor?
Can someone provide a good example in Java 7?
i am developing an app with phonegap 2.2. I have been able to implement a background service from https://github.com/Red-Folder/Cordova-Plugin-BackgroundService.
right now i want to be able to listen for changes in the contacts database such that when a change is detected, a function can run in the background service (Java Method).
How can this be implemented.
You have to create a content observer in your service and register that observer to listen for changes in contacts database.
Here is an example of contacts content observer:
ContactsContentObserver contentObserver = new ContactsContentObserver();
private class ContactsContentObserver extends ContentObserver
{
public ContactsContentObserver()
{
super(null);
}
#Override
public void onChange(boolean selfChange)
{
super.onChange(selfChange);
// handle change received
}
}
You can register the content observer in service onStart() method:
getContentResolver().registerContentObserver (ContactsContract.Contacts.CONTENT_URI, true, contentObserver);
And unregister it in service onDestroy() method:
getContentResolver().unregisterContentObserver(contentObserver);
Hope it helps.