Android :: How To Use Intents From Service Or Broadcast Receiver?

Dec 15, 2009

I need to be able to handle/catch Intents while my Activity is closed. So I am looking at either a Service or a BroadcastReceiver. Is it possible to "receive" intents to a service itself? I tried to search, but could not find anything helpful. With a BroadcastReceiver, I am not exactly sure how that works outside of an Activity. Does it depend on the Activity being open/running? Can it run by itself?

Let's say that my Activity is killed by Android(or a task killer app), does the BroadcastReceiver still receive intents and process them? I have used a BroadcastReceiver as a widget, but I do not want to use a widget this time. My goal is to have the user open the Activity to set some options. From there, they would be able to close the Activity, but I would still be able to process Intents that were sent out by the system. I am still fairly new to Android development, so I could be so far away from where I need to be.

Android :: How to use Intents from Service or Broadcast Receiver?


Android :: Receiving System Intents With Custom Broadcast Receiver

Jul 16, 2010

I am attempting to listen for system fired Intents, specifically regarding text input, using a class extending BroadcastReceiver. I see there is an Intent called ACTION_INPUT_METHOD_CHANGED (android.intent.action.INPUT_METHOD_CHANGED) which I hope to be able to use to know when the keyboard or text input is attempted by the user. (I assume this intent will work as I can use an InputMethodManager object to handle keyboard related tasks)

My java code:
package com.BroadcastReception;
import android.content.BroadcastReceiver; import android.content.Context;
import android.content.Intent; import android.util.Log;
public class InputMethodChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
if (arg1.getAction().equals("android.intent.action.INPUT_METHOD_CHANGED")) {
Log.d(this.toString(), "Event Fired");} } }

View 5 Replies View Related

Android :: Sending Intents From Receiver To Service With Delay

Aug 18, 2010

I have a Receiver for BOOT_COMPLETED intent and it will start a Service by calling startService with an intent and the Service processes that intent in onStartCommand function by spawning a thread that does a HTTP post to a server.On powerup, sometimes it takes 3 to 5 seconds to get the active data connection on phone, when this happens Service fails to do HTTP post as there is no data connection. Is it possible for the Receiver to send the intent to Service using startService with a delay.? so that when onStartCommand of Service is called data connection is ready to post data.

View 2 Replies View Related

Android :: Android - Registering Broadcast Receiver For Two Intents?

Feb 23, 2010

I was wondering is it possible to register a broadcast receiver to receive two intents? My code is as follows:

sipRegistrationListener = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(SIPEngine.SIP_REGISTERED_INTENT.equals(action)){
Log.d("SETTINGS ", "Got REGISTERED action");
} if(SIPEngine.SIP_UNREGISTERED_INTENT.equals(action)){
Log.d("SETTINGS ", "Got UNREGISTERED action");
} } };
context.registerReceiver(sipRegistrationListener, new IntentFilter(SIPEngine.SIP_REGISTERED_INTENT));
context.registerReceiver(sipRegistrationListener, new IntentFilter(SIPEngine.SIP_UNREGISTERED_INTENT));

I get the registered Intent everytime I send it but I never get the unregistered Intent when I send it. Should I set up another Broadcast receiver for the unregistered Intent?

View 1 Replies View Related

Android :: Broadcast Receiver - Create A Broadcast Receiver Which Responds To System Events

Sep 28, 2009

trying to create a broadcast receiver which responds to system events and change system settings. I don't need any interaction from the user so I don't need an activity and have been trying to do everything through the manifest file. I've put a log event into my onReceive method but it never logs anything so I'm presuming my method is never called. I've tried this with both the 1.5 and 1.6 SDKs. I was hoping somebody could have a look at my code please and let me know if there are any problems.

View 2 Replies View Related

Android :: Broadcast Receiver / Service & Thread

Jun 23, 2010

I am starting to develop a new app and I am a bit confused about the structure I need to give it.I need to react to broadcast intents, so I placed a broadcast received in the manifest. Every single intent produces an action to be performed. Now the first question: should I start a service (maybe with non_sticky option?) or should I start a thread (or an async task) directly from the broadcast receiver? If I start a service, should I do all the stuff in its body, or should it start a thread. I should do the heavy job in a thread if there are time consuming operations, but what if the gui of my application is just an activity with the options and a button to start the service. What is the point in keeping the main thread busy? Do I risk to be killed for not being responsive? I read here and there that I can update the gui from a background thread. Can I do that even if it is started from a service? The AsyncTask's onProgressUpdate is said to run in the application main thread, but if the application is made of different activities, who tells me which activity is the user looking at while the thread is doing all its long work? The user could change activity in the meanwhile and then the update would be unuseful.I know it's (quite) a lot of questions, but I need to get some clarifications before taking the wrong path.

View 5 Replies View Related

Android :: Broadcast Receiver And Remote Service

Jan 20, 2010

I'm hoping to do some audio processing in a remote service (service I've spawned onto its own thread); this will basically occur in a while (1) loop so constant processing. Occasionally I want to provide some information back to the activity that is bound to the service; I'm doing this by sending a broadcast from the service, that is received by a broadcast receiver on the activity, which then uses the activity's service connection to call into the service and get the information needed; at this point the broadcast receiver makes an alert dialog presenting the information to the user.If I stay in my while(1) loop after raising the broadcast, the action in the broadcast receiver never seems to occur.This is confusing to me since the activity and service are in separate threads.If I end the loop after raising the broadcast, the desired behavior on the activity side occurs, but of course this isn't acceptable since I need to be doing constant processing.

View 11 Replies View Related

Android :: Broadcast Receiver / Service Will Only Restart Activity Once

Mar 17, 2010

I have a single Activity application, within it I have a service which creates an AlarmManager and sends a broadcast to a broadcast Receiver.If the activity which starts the services dies, (ie. divide by zero), the broadcast receiver stops the old service which created the AlarmManager.It works the first time. The second time, it does not.It seems like the AlarmManager is still active but the broadcast receiver is no longer receiving. It works great once!

View 2 Replies View Related

Android :: How To Communicate Back To Service From Broadcast Receiver?

Aug 17, 2010

I have a widget which starts a service. The service registers two broadcast receivers. I would like to send back intents from the receivers to the service, so that the service can react.I remember reading (on some blog) that this won't start a new service, but will simply pass the intent to the already running service. Is this correct? Is it a bad way of doing it? Is there a better way?

View 1 Replies View Related

Android :: Keep Broadcast Receiver Process Alive / By Creating Service That Stays Around?

Sep 16, 2009

The app widget documentation indicates that the "widget provider"being a receiver of a broadcast service may not exist (the process) beyond the completion of the call.If I want to maintain state between two broadcast events, such as say widgetProvider.onUpdate(), can I start a local service and leave it hanging there until my widgets are disabled? If I didn't explicitly stop that service will it be loaded again and resumed when the device wakes up.

View 4 Replies View Related

Android :: Need To Implement "broadcast Receiver" Functionality In My Service?

Nov 18, 2010

I have to handle "power down" event in my service, but so far I couldn't find how to receive "power down" event...Do I need to implement "broadcast receiver" functionality in my service? I would appreciate some pointers.

View 2 Replies View Related

Android :: How Different Do Broadcast Intents Need To Be?

Oct 30, 2010

I have an IntentService that broadcasts an Intent each time if finishes some work. Each broadcast Intent is identical except that it contains a Bundle with some result information from the IntentService. Evidently, having different data in the Bundle is not enough for Android to think it's a different Intent. If the IntentService broadcasts two of these Intents back-to-back, the second one is dropped as a duplicate.

I know I've read about this behavior in this forum in the past but I can't find in the documentation where this duplicate elimination logic is described in detail. Mostly, I just want to differentiate the Intents enough that they are not considered duplicates. Any pointers would be appreciated.

View 13 Replies View Related

Android :: Using Broadcast Intents / Phone State Changes

Jun 29, 2010

I was just working on an application that will do stuff when a call is missed or made; and am left wondering why do you have to register a listener using a long lived background service for phone state changes instead of being able to use broadcast intents?

View 2 Replies View Related

Android :: List Of All Calendar Broadcast Intents?

Jun 9, 2009

I'm trying to capture when a calendar reminder goes off. What I'm trying to do right now is use a BroadcastReceiver and receive an intent from the calendar. Is there an intent that gets broadcast when a calendar reminder goes off? If so what is its name, or where can I find it? Is there a list of all the calendar intents somewhere?

View 3 Replies View Related

Android :: Broadcast Receivers Not Receiving Pending Intents

May 20, 2009

I've had an issue where no matter how I've tried to set it up I'm finding the Broadcast Receivers aren't receiving any Pending Intents. A look through LogCat confirms that the intents are launched, but they're not being executed. I managed to make a simple(ish) repro case. If you take the SimpleWiktionary widget by Jeff Sharkey http://code.google.com/p/wiktionary-android/ and make the following changes plus any required imports. Code...

View 8 Replies View Related

Android :: Start TTS From Broadcast Receiver

Jul 9, 2009

I am trying to start TTS from a broadcast receiver and it as document an intent receiver can't bind the service. Is there a work around, I can't figure out how to start the service using startService(Intent, Bundle).

View 4 Replies View Related

Android :: Broadcast Receiver Without Activity

Feb 12, 2010

A WAP PUSH (Broadcast)receiver basically doesn't need any UI. It is a silence application which handles the Push messages based on actions/ mimetype without needing any intreaction with user, I've tried to test it in a SMS receiver by removing the Activity from the project and it stopped receiving the SMS messages. My question: Does all android applications "MUST" define a activity? Is there a way to hide it?

View 5 Replies View Related

Android :: Broadcast Receiver Error

Jul 23, 2010

I am working on one project where i am using broadcast receiver in one of my activity to capture the incomming call and its works fine. when one of my other activity is open and that time if call is come then my broadcast receiver is fail to respond. can any one help me for this ? or its nessesorry to declare broadcast receiver in all my activity to do some comman task.

View 5 Replies View Related

Android :: Broadcast Receiver From Widget

Dec 2, 2009

I am making a widget that needs a broadcast receiver, like the one in com.example.android.apis.appwidget.ExampleBroadcastReceiver. However, the example defines Intent.ACTION_TIMEZONE_CHANGED in the manifest, but there are some that do not allow this. For example, Intent.ACTION_TIME_TICK says "You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver(). "

So I removed the manifest declarations and tried replacing the AppWidgetProvider.onEnabled function that was in the example with a call like the following: context.registerReceiver(myReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
(where "myReceiver" is an instance of the receiver I want.) However, when I try to run the code, I get the following error:
Unable to start receiver...android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents.
Any way to get this broadcast receiver working from a widget?

View 3 Replies View Related

Android :: Any Other Application As Broadcast Receiver?

Jul 29, 2009

I am broadcasting an Intent from an activity. Can we make another application as a receiver. So that it will get invoked when that specific intent is broadcasted.

View 2 Replies View Related

Android :: Broadcast Receiver Sometimes Works

Jan 6, 2010

I wish to listen to android.intent.action.BOOT_COMPLETED. However I am not getting the broadcast intent, if I specify com.test.BootBroadcastReceiver in the manifest. When I change this value to simply BootBroadcastReceiver, then I am getting the broadcast intent.

<receiver android:name="BootBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

My package in the manifest file is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
And the BootBroadcastReceiver resides in this package. What is the reason behind this?

View 2 Replies View Related

Android :: Trying To Understand Use Of Broadcast Receiver

Aug 17, 2009

I have an application that uses an extended Broadcast Receiver class inside the Activity. I have the extended Broadcast Receiver class as a member variable of the Activity class. But it looks like the receiver references keep changing between its construction and 'on Receive' method call. I would like to understand this better. Here are some details. public class MyEventReceiver extends Broadcast Receiver

View 3 Replies View Related

Android :: Broadcast Receiver For Action

Oct 3, 2009

I was wondering if its possible to have a broadcast receiver to listen when the app its in launches.I tried doing by creating a BroadcastReceiver to listen for the android.intent.action.MAIN action but it never gets called?Is there something I need to do or a different action I should be listening for?

View 3 Replies View Related

Android :: How To Use Broadcast Receiver In Different Applications?

May 1, 2010

I have here two applications in two different projects in eclipse. One application

(A) defines an activity

(A1) which is started first. Then i start from this activity the second activity

(B1) in the second project

(B). This works fine.

Unfortunately, the message is never received. Although the method in activity A1 is called, i never receive an intent in B1.

View 1 Replies View Related

Android :: Broadcast Receiver For Sent SMS Messages?

Jun 13, 2009

I created a BroadcastReceiver and configured it with an android.provider.Telephony.SMS_RECEIVED action filter so it is called everytime the phone receives a text.Is there some event/action or other way for my application to be notified whenever the phone sends a text (preferably independent of the application that sends it)?So far the only option I see is to poll the content provider for content://sms/sent which doesn't even give me all sent texts because applications can choose not to put it there.

View 1 Replies View Related

Android :: Set Priority To Broadcast Receiver

Oct 24, 2010

The symptom: I have a broadcast receiver that listen to sms, when a sms is received, i call an activity to display. It works all fine if the screen is on and not locked. But when screen is locked, and as soon as i received the sms, the activity popup for a second then disappeared and I use the code to unlock the screen.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

I think it might be the competitions with phone default sms program (the sms default program shows a notification only). I am wondering is there a way to set priority to broadcast receivers or even the activity that receiver stared, to avoid the conflicts between multiple receivers. or set orders to execute one by one? I have tried to thread.sleep my receiver for a second, still not working.

View 2 Replies View Related

Android :: Error In Receiving SMS Using Broadcast Receiver

Oct 11, 2010

I'm trying to receive SMS using broadcast receiver. MySMSReceiver :

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class MySmsReceiver extends BroadcastReceiver {
/** Tag string for our debug logs */
private static final String TAG = "MySmsReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Recieved a message");
Bundle extras = intent.getExtras();
if (extras == null)
return;
Object[] pdus = (Object[]) extras.get("pdus");
for (int i = 0; i < pdus.length; i++) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
String fromAddress = message.getOriginatingAddress();
String fromDisplayName = fromAddress;

Log.i(TAG, fromAddress);
Log.i(TAG, fromDisplayName);
Log.i(TAG, message.getMessageBody().toString());
break; } } }

and added in Mainfest file
<receiver android:name=".MySmsReceiver" android:enabled="false">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS" />

But when I run this application and send a SMS using emulator it shows following logs in logcat

10-12 00:14:53.082: VERBOSE/Telephony(1032): getOrCreateThreadId uri: content://mms-sms/threadID?recipient=9898989898
10-12 00:14:53.203: VERBOSE/Telephony(1032): getOrCreateThreadId cursor cnt: 1
10-12 00:14:53.432: DEBUG/Mms:app(1032): getSmsNewMessageNotificationInfo: count=4, first addr=9898989898, thread_id=3
10-12 00:14:53.482: WARN/NotificationService(62): STOP command without a player
10-12 00:14:53.562: DEBUG/MediaPlayer(62): Couldn't open file on client side, trying server side
10-12 00:14:53.582: ERROR/MediaPlayerService(34): Couldn't open fd for content://settings/system/notification_sound
10-12 00:14:53.592: ERROR/MediaPlayer(62): Unable to to create media player
10-12 00:14:53.643: WARN/NotificationService(62): error loading sound for content://settings/system/notification_sound
10-12 00:14:53.643: WARN/NotificationService(62): java.io.IOException: setDataSource failed.: status=0x80000000
10-12 00:14:53.643: WARN/NotificationService(62): at android.media.MediaPlayer.setDataSource(Native Method)
10-12 00:14:53.643: WARN/NotificationService(62): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:716)
10-12 00:14:53.643: WARN/NotificationService(62): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:671)
10-12 00:14:53.643: WARN/NotificationService(62): at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:8)

View 1 Replies View Related

Android :: Sometimes Receiver Not Receiving Any Broadcast Message

Sep 10, 2010

I have create a receiver which receive on phone state change I have register it in XML by "android.intent.action.PHONE_STATE"

But sometime it don't receive any broadcast message
log mesages are:::

09-10 11:20:36.968: WARN/ActivityManager(74): Timeout of broadcast BroadcastRecord{43347258 android.intent.action.PHONE_STATE - receiver=android.os.BinderProxy@4334ebd0
09-10 11:20:36.968: WARN/ActivityManager(74): Receiver during timeout: ResolveInfo{432dd748 com.callHandller.PhoneStateReciever p=0 o=0 m=0x108000}
09-10 11:20:36.968: INFO/Process(74): Sending signal. PID: 2223 SIG: 9
09-10 11:20:36.988: ERROR/JavaBinder(74): !!! FAILED BINDER TRANSACTION !!!
09-10 11:20:37.008: INFO/ActivityManager(74): Process com.callHandller (pid 2223) has died.
09-10 11:20:37.008: INFO/WindowManager(74): WIN DEATH: Window{4324f470 com.callHandller/com.incallHandller.callHandler paused=false}
09-10 11:20:37.958: WARN/ActivityManager(74): Activity destroy timeout for HistoryRecord{4321c7c0 com.callHandller/com.incallHandller.callHandler}
09-10 11:20:42.288: DEBUG/dalvikvm(136): GC freed 2543 objects / 143320 bytes in 179ms
Here com.callhandller is my application package where I have Receiver...

View 3 Replies View Related

Android :: Added Broadcast Receiver In Manifest

Jul 11, 2010

So, I added the receiver (contained in application) in the manifest. Broadcast doesn't fire my broadcast receive.

<receiver android:name="mypkg.IncomingCallReceiver">
<intent-filter>
<action android:name="android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED"/ >
</intent-filter>

View 4 Replies View Related

Android :: Understanding Broadcast Receiver / Way Of Activate It

Mar 25, 2010

I am trying to understand the use of the broadcast receiver and the way of activate it. There's two ways isn't it? Register it from an activity or declare it in the manifest. So my question is: If I code a broadcast receiver which is watching incoming messages and I register it in the manifest, when a message comes my broadcast receiver will catch it automatically although any activity of my app had registered it. In a nutshells, I don't have to activate it so it works, only register it either in the manifest or in an activity.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved