I have a service that fires off every 5 minutes or so... How would i query android to see when this service is scheduled to go off programatically?
<!-- Send Census Service -->
<service android:name="services.scheduled.SendCensusScheduledService"
android:icon="#drawable/ic_launcher"
android:label="SyncServerDataScheduledService" />
<receiver android:name="services.receivers.SendCensusScheduledServiceReceiver" >
<intent-filter>
<action android:name="ReceiptBucketClient.android.action.broadcast"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="services.receivers.StartSendCensusScheduledServiceReceiver" />
Check by the PendingIntent:
PendingIntent intent = PendingIntent.getBroadcast(context, 0,
new Intent("ReceiptBucketClient.android.action.broadcast"),
PendingIntent.FLAG_NO_CREATE;
if (intent != null) {
// you have the service scheduled. Cancel it!
intent.cancel();
}
Remember that only the original application owning a PendingIntent can cancel it.
Related
In my code I have a broadcast reciever
<receiver
android:name=".alarm.AlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
<intent-filter>
<action android:name="com.BalDroid.YekNegah.alarm.dailyAction"
/>
</intent-filter>
</receiver>
I schedule alarm in this receiver in onReceive method
PendingIntent pi = PendingIntent.getBroadcast(context, AlarmRow.getId(mycursor), i, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= 21) {
AlarmManager.AlarmClockInfo alarmInfo = new AlarmManager.AlarmClockInfo(
mycal.getTimeInMillis(),pi);
mgr.setAlarmClock(alarmInfo,pi);
// Create a Pending intent to show Alarm Details
}
although receiver run but alarm not trigger with mgr.setAlarmClock. But when I use
mgr.setExactAndAllowWhileIdle alarm trigger
(because of setAlarmClock accuracy I have to use setAlarmClock in my code)
And when I schedule mgr.setAlarmClock from MainActivity (when start application manually) it works.
I cant find the solution!!.
(I don't know why is not work from receiver).
My app also called setAlarmClock on AlarmManager, however the event didn't trigger. The reason for me was the default restriction of background processes by the manufacturer(my phone is Xiaomi).
Go to Settings -> Your application and find background restriction options. Turn the restrictions off and setAlarmClock must work.
As a conclusion, the result depends on manufacturer's default settings.
Long time = prefs.getLong("dailynoti", 0);
Intent intent = new Intent(cn, NotificationReceiver.class);
intent.putExtra("Desc", "Description...");
PendingIntent pendingIntent = PendingIntent.getBroadcast(cn, 1055, intent,0);
AlarmManager alarmManager = (AlarmManager) cn.getSystemService(cn.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,time, AlarmManager.INTERVAL_DAY, pendingIntent);
and my mainifest file
<receiver
android:name="com.mypackage.NotificationReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
And this same code is use in same project but now in same project another module it will not work Broadcast Receiver isn't call at given time
my notification code is in Receiver file but Receiver class isn't call.
I checked all things like time is also get properly. so what is the problem . please help...
I used many solution like
PendingIntent pendingIntent = PendingIntent.getBroadcast(cn, 1055, intent, PendingIntent.FLAG_CANCEL_CURRENT
//FLAG_NO_CREATE
//FLAG_UPDATE_CURRENT
One approach that I think that will work is instead of alarmManager.setRepeating() use alarmManager.set() and when the alarm triggers then set the next alarm. This will give you almost accurate results. Why almost? Because due to Doze mode introduced in Android M. So this will give you between 0 to +5 min delay.
I am having a problem with my application's broadcast receiver.
I have a situation where I wan the broadcast receiver to be called for 3 different reasons, first phone state changed, second, based on a timer, and third on boot complete. And then according to the reason by which the broadcast receiver was called I want to be able to do some stuff.
below is my android manifest of my receiver:
<receiver android:name="com.example.mobileraptor.MyPhoneListener" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.example.mobileraptor.TimerTriggered" />
</intent-filter>
</receiver>
and the following is where i declare my TimerTriggered intent:
PendingIntent pintent = PendingIntent.getBroadcast( this, 0, new Intent("com.example.mobileraptor.TimerTriggered"), 0 );
AlarmManager manager = (AlarmManager)(this.getSystemService( Context.ALARM_SERVICE ));
manager.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_HOUR , pintent );
The problem is that once the application wants to boot it crashes. but if I comment the line :
action android:name="com.example.mobileraptor.TimerTriggered
then my application is fine.
what is wrong with the action name that I have defined.
I am using an AlarmManager to start a service that runs every minute. However, I am getting the "The application blabla has stopped unexpectedly." warning dialog with Force Close button when I turn on the device. I do not know what the error is because the only debugging option I have is with WIFI and the IP of the connection changes every time I reboot the device.
The service runs fine without the boot.
Here is my BroadcastReceiver running under the application:
public class FPBootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
android.os.Debug.waitForDebugger();
Intent bootintent = new Intent(context, FPService.class);
PendingIntent pi = PendingIntent.getService(context, 0, bootintent, PendingIntent.FLAG_UPDATE_CURRENT);
long nextUpdateTimeMillis = DateUtils.MINUTE_IN_MILLIS;
Time nextUpdateTime = new Time();
nextUpdateTime.set(nextUpdateTimeMillis);
AlarmManager FPAlarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
FPAlarm.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), nextUpdateTimeMillis, pi);
}
}
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="#drawable/pc"
android:label="#string/app_name" >
<service android:name=".FPService" />
<receiver android:enabled="true" android:name="mypackage.FPBootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity
android:name=".CF_Aachen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Anything wrong you see that I am doing wrong with these?
UPDATE: Managed to debug the boot and I am getting AndroidRuntime(2781): java.lang.RuntimeException: Unable to instantiate receiver mypackage.FPBootReceiver: java.lang.ClassNotFoundException: mypackage.FPBootReceiver in loader dalvik.system.PathClassLoader
Android system can not see your Receiver, check your path unless your full package is actually "mypackage". You ether need to make it ".mypackage.FPBootReceiver" or specify the full path.
I wrote my BroadcastReceiver class under the same class of my Activity. That's why it was unable to find it.
I created a seperate class file in mypackage and created the class there and then it was solved.
Thanks to all who advised.
I use Broadcast Receiver, WidgetProvider and Configure Activity. Activity starts during the creation of a widget. Widgets are updated every 20 seconds.
private PendingIntent service = null;
Intent intent = new Intent(context, AlarmReceiver.class);
if (service == null) {
service = PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
m.setRepeating(AlarmManager.RTC, TIME.getTime().getTime(), 1000 * 20,
service);
I whant to update widgets when I change time or timezone on my phone. Widgets are updated when I change the time ahead. But when I change the time back, nothing happens.
I've already added to the manifest
<receiver android:name=".AlarmReceiver" >
<intent-filter>
<action android:name="android.intent.ACTION_TIMEZONE_CHANGED" />
<action android:name="android.intent.ACTION_TIME" />
</intent-filter>
</receiver>
In the Broadcast Receiver I'm updating widgets.
Please refer to
http://developer.android.com/reference/android/content/Intent.html#ACTION_TIMEZONE_CHANGED
They should be
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />