I have a widget that updates the time every minute using a repeating alarm. The widget also registers in the manifest for the USER_PRESENT intent and when this is received, it checks if the time updating alarm is running; if not, it starts it.
The above works for most devices. On some devices though, it looks like the widget stops receiving the USER_PRESENT intent when the device goes into deep sleep (the repeating alarm also stops firing). The widget process is not killed by the system because clicking on the widget causes it to start working again.
Any ideas on what could be the problem?
Here is the widget receiver definition:
<receiver android:name=".timeWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.test.UPDATE" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="#xml/widget" />
</receiver>
Related
So, I have an alarm application which works good and behaves normally as long as the device remains online until the alarm time.
Problem is, let's say I ran out of battery, or I just want to restart the device... the alarm won't fire upon its time.
I tried something like:
public class BootCompletedReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Utils.set_alarms(context);
}
}
}
In my BroadcastReceiver... but doesn't seem to work. Oh, and it's registered in the AndroidManifest too...:
<receiver
android:name=".receivers.AlarmReceiver" // The receiver which starts the alarm activity.
android:enabled="true" />
<receiver
android:name=".receivers.BootCompletedReceiver" // The receiver which is supposed to set the alarms after the device is online again.
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
But doesn't work... help will be appreciated.
You probably need to add the permission to receive boot completed to your manifest. See Manifest Permission: RECEIVE_BOOT_COMPLETED
Add below permission and actions
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".receivers.BootCompletedReceiver" // The receiver which is supposed to set the alarms after the device is online again.
android:enabled="true">
<intent-filter>
<!-- used for restart or reboot -->
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<!-- Used for cold boot -->
<action android:name="android.intent.action.BOOT_COMPLETED" />//cold start
</intent-filter>
</receiver>
I want to write a screen capture app, but I don't know how to trigger my app globally by special action such as shaking the device or long press a button or anything else. Which means bring up my app under any app any time. Is there any suggestion?
You'll need to use a reciever for that. For example, if you wanted the app to start activity MyReciever when the phone boots up, you could do the following:
<receiver android:name=".MyReceiver">
<intent-filter >
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I'm working on a widget that displays information from a completely separate app. The separate app sends a broadcast when its data is changed, and I want to refresh/update my widget upon receiving this broadcast.
I can't seem to work out how to update a widget from within a BroadcastReceiver however. Is there a way to do this? Or another method to get the same result?
If the separate app has special action for its broadcast, you can add the intent filter to the manifest of your widget. Something like this:
<receiver android:name="ExampleAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="SEPARATE_APP_ACTION" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/example_appwidget_info" />
</receiver>
And just process it in onRecive method of you AppWidgetProvider.
HTH.
Currently I have a service, TimerService, that broadcasts updates, milestones, and alerts.
In the manifest file:
<!-- WIDGET! -->
<service android:name=".UpdateWidgetService" android:permission="android.permission.BIND_REMOTEVIEWS" ></service>
<receiver
android:icon="#drawable/icon"
android:label="JustInTime"
android:name="com.JustInTime.widget.WidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
Would the UpdateWidgetService register receivers for the TimerService? It seems wrong that one service is listening to another service like this. Also, is it normal to register onClick functionality within the widget, or do you have to use setOnClickPendingIntent?
Goal: To have a widget that works like an alarm clock that listen to broadcasts from a service and then updates the widget as it needs. This update should update the UI, where there are several view items.
If you have good widget examples from this, please share. Most of them are very basic from what I see.
In my application I have a service that after for example 30 seconds, runs another activity. I did this process with Alarm Manager.
But the problem is, if the user changes the system time it affects 30 seconds. What is your suggestion? Is there any way to know if the user changes the system time?
You can listen to Intent.ACTION_DATE_CHANGED broadcast. Your ApplicationManifest file should contain something like
<receiver android:name="com.test.YouBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
</intent-filter>
</receiver>
For broadcast receivers refer:
http://developer.android.com/reference/android/content/BroadcastReceiver.html