I have an Activity. This Activity runs a Service. The Service runs a BroadcastReceiver.
In the Service or BroadcastReceiver I need to write some data to a database. So I instantiate my DB Helper class. Yeah buddy...I get about 100 "In Constructor" messages and than a Stack Overflow FC. Woo Hoo!
I'm stumped as to where I can instantiate the DB Helper so I can write my data.
Related
SMS2PC API
Introduction
It is with great pleasure that today I am releasing the first public beta of SMS2PC API which is designed to allow developers and hackers to quickly and easily send and receive messages via an Android (and soon to be BlackBerry and WinPhone) device as well as loading contact information and address credentials.
The API is designed in an async like manner allowing you to create a request, forget about it and then easily handle any return to the original request while not having to worry about threads, connections and protocol management. As an example, you can send a message with only a few lines of code and then handle delivery notifications and send notifications when they occur by providing a callback that is fired when a the message's status has changed.
You are free to use the API as you wish. You will be able to do things like send messages from a server to notify of events on the server, you could make an application than can receive commands such as ‘shutdown_pc’ via SMS and then shut down the current PC, run in on embedded systems, create alarm system that notify via SMS of intruder etc!
Features
Current
Send message
Handle Delivery Notifications
Handle Send Notifications
Load Contact Details
Receive incoming message from device.
Loading message list for a contact
Upcoming
MMS Support
Inbox Support
Load advanced contact details
Example of Handling Incoming Messages
As an example to highlight how simple it is to receive new messages when the arrive on device the actual code used is provided below.
Code:
class MyHandler implements IMessageReceiveHandler
{
@Override
public void messageReceived(Message message)
{
System.out.println("New message received: " + message.getBody());
}
}
// Create instance of your handler and provide it to the API
MyHandler myMessageHandler = new MyHandler();
sms2pc.setMessageReceiveHandler(myMessageHandler);
Requirements
Current the API is Java based (requiring JRE). We have nearly finished the C# version and the mobile apps for BlackBerry and WinPhone will be available shortly.
Terms of Use
Please be aware that although you are totally free to use the API in any software as you choose (commerial or personal) , the Android/BlackBerry & WinPhone app is currently paid for at around £1.99. Also, if you use SMS2PC API in your software you must provide a mention of this fact in your about/info dialog or help if console application. This may be updated in the future although the price will never increase. If you are an XDA user you can download SMS2PC API for free for Android but must not re-distribute the apk.
Conclusion
Thank you for reading. If you have any questions feel free to email me at [email protected] or PM me.
Can't wait until the c# version is done ^_^
Any chance you plan on fixing the desktop app to work with Lion or Mountain Lion?
It's only $3, but you've got it (literally tried to refund moments later and couldn't), and the app flat out does not work on Mac OSX.
Great work, can you show an example on how to send sms?
I am a complete newbie in Android.
I am developing an application that sends over a webservice information about the last dialed number, call status, and duration of the call.
The application works perfectly fine, but when the device closes the application the android service does restart but the activity does not.
The way I am sure about that is that I have Toasts when the service is started: "Servicio TRUCKA iniciado" and "Servicio TRUCKA creado" tell me that the service has been created and started.
And when the information is sent to the webservice I have toasts saying: "Enviando información..." and "Información enviada."
But when the application is closed (via the android task manager that automatically closes apps) the messages from the service "Servicio TRUCKA iniciado" and "Servicio TRUCKA creado" do appear, but the toasts from the information sent part do not.
I hope someone can help me and tell what am I doing wrong?
Really really thanks a lot!
I can not add code to the post, so I am adding the project hoping someone can help me
CLOSED
Human stupidity has no limits.
My actions where not in the service
Hello all,
I have a question about Android service and broadcast.
For my application I am trying to keep track of the time with the Timer class.
The user can press a button and a timer will increase his value. (visible in activity).
What I am trying to achieve is to keep this timer going even if the user closes his application.
And after some specific time (say like every 10 mins) I want to send the user a notification to let him know the timer is still running.
Am I using the right implementation for using a service and broadcast?
I'd say there is no need for any broadcasts.
The Service can keep track of the Timer and Notification, then your Activity either starts and binds to the Service or if the Service is already started it rebinds.
Then use a PendingIntent to either stop the Service or start the Activity on Notification clicks, depending on your flow.
registered-user said:
I'd say there is no need for any broadcasts.
The Service can keep track of the Timer and Notification, then your Activity either starts and binds to the Service or if the Service is already started it rebinds.
Then use a PendingIntent to either stop the Service or start the Activity on Notification clicks, depending on your flow.
Click to expand...
Click to collapse
Thanks for your reply! I meant alarmmanager sorry! My idea was to check every x amount of time with my alarmmanager if my service (timer) is still running. Or is there also no need for a alarmmanager?
I guess you could do that, depends on the overall goal. You could also create a static flag in your Service that is flipped on start and on stop. Then post a delayed runnable/message to check the flag?
This set of Apps will allow you to receive notifications on your secondary devices such as:
- The tablet you use away from the phone.
- The small mobile that you use for sports and leave your house phablet in safekeeping.
- Your SmartWatch with Android - You can use bluetooth
Now you can receive notifications, sms and calls
Installation
Once installed and configured M2D Notifications Sender on your main phone (which usually use), this forward notifications to your (max 3) secondary devices so you can read them while away from your main phone (if they have internet access) and in many cases will leave you answer them.
On your tablet, or mobile accessory or even watch android, you must install M2D App Notifications Receiver and once configured, you can receive and reply notifications.
Configuration
*** Now you can use Bluetooth as well
For devices can look them eatch others, you need to enter in the App M2D Sender the Receivers codes. This code is shown on the display settings of the M2D Receiver App once it is installed on your secondary device.
In the Receiver M2D App you must enter the IMEI of the main device. This imei is shown on screen settings of the M2D Sender App once installed in your primary device.
There are other security parameters to avoid that anyone can send messages to your device.
On the M2D Sender App you must enter your own key and in the M2D Receiver App the same key that must match since otherwise the messages will be discarded. This key allows the Sender to send messages and that the Receiver will accept. By default Apps already have this code included, but you better change them.
On the M2D Receiver App you must enter your own key and in the M2D Sender App the same key that must match since otherwise the messages will be discarded. This key allows the Sender to send messages and that the Receiver will accept. By default Apps already have this code included, but you better change them.
Additionally, messages are encrypted so that only the recipient can read them. For this an encryption key is used in the settings. By default Apps already have this codebook including, but you better change them.
Replying
In addition to receiving notifications, in many cases, action buttons will appear with different options, including reply ones.
You can reply with predefined options and also with the keyboard as usual.
Every time you send an action, we will receive a message with the status of such action, for example if the message was sent or not.
To avoid synchronization issues notifications viewed on the main device are not automatically removed and vice versa.
Sending whatsapp
The M2D Receiver App has a button that can send messages to contacts we have previously received whatsapp messages. This depends on if there are unread messages in whatapp when a new notification arrives, but the app will always be learning and allows you to write to more contacts.
How does it work
- Notifications are encrypted and send with the key configured on the server Apps.
- The server checks the sender and receiver data to see if they are registered and if so sends the message to Google using GCM (What's this?)
- When the Receiver has internet, Google shall forward the notification to Receiver
- The receiver decrypts the message and checks that the keys to Sender and Receiver match
- The receiver displays a notification to the user
In the case of the answers is similar, but completely upside down.
Privacy
The server never stores the message that it receives, it only makes like a proxy for shipment and is very light.
Further messages are encrypted with the encryption key (change those default)
Apps
M2D Sender: https://play.google.com/store/apps/details?id=com.pacosal.m2d.notifications
M2D Receiver: https://play.google.com/store/apps/details?id=com.pacosal.m2d.receiver
M2D Bluetooth Manager https://play.google.com/store/apps/details?id=com.pacosal.m2d.manager
Enjoy!
Original thread here http://forum.xda-developers.com/android/apps-games/app-m2d-notifications-sender-receiver-t2986778
GREAT app. M2D user here. Thanks.
Hello, there. I'm trying to setup M2D on a Amazfit Pace (Android 5.1, MIPS processor). The Receiver app installs, but FC when I try to open it. I didn't find anything about Amazfit on this thread, so it's a known bug? Maybe this can be fixed in the future? I think M2D would be very useful for Pace owners, so the watch can receive notifications on WiFi as well. Thank you!
Do you know what error is giving you? Could you see the logcat?
Logcat from my Amazfit stratos
03-23 21:33:43.975 2234-2234/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pacosal.m2d.manager, PID: 2234
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pacosal.m2d.manager/com.pacosal.m2d.manager.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:332)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3409)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3724)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:400)
at android.app.Activity.setContentView(Activity.java:2145)
at com.pacosal.m2d.manager.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)*
at android.app.ActivityThread.access$800(ActivityThread.java:151)*
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)*
at android.os.Handler.dispatchMessage(Handler.java:102)*
at android.os.Looper.loop(Looper.java:135)*
at android.app.ActivityThread.main(ActivityThread.java:5254)*
at java.lang.reflect.Method.invoke(Native Method)*
at java.lang.reflect.Method.invoke(Method.java:372)*
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)*
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)*
03-23 21:33:43.984 432-566/? W/ActivityManager: Force finishing activity 1 com.pacosal.m2d.manager/.MainActivity
03-23 21:33:44.007 432-679/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected]
03-23 21:33:44.536 432-453/? W/ActivityManager: Activity pause timeout for ActivityRecord{3f71c65e u0 com.pacosal.m2d.manager/.MainActivity t422 f}
Thanks, difficult to fix that without the watch. Possibly there will be more errors than that one.
Regards
Is there some sort of a listener that I can register for that listens for new processes that are created? I would like to get the process name, pid, and the uid from it.