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
Related
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>
I want to use BroadcastReceiver like this
<receiver android:name=".receivers.MediaReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.hardware.action.NEW_PICTURE" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.hardware.action.NEW_VIDEO" />
<data android:mimeType="video/*" />
</intent-filter>
</receiver>
I had read Using the JobScheduler API on Android Lollipop,but I still don't know how to do.
I'm not sure if this was your original question, but I came across this because of the deprecation of WakefulBroadcastReceiver, which was previously the standard way of listening for an intent and then doing activity that requires a wake lock.
The answer is that you should still use BroadcastReceiver to receive intents like you've set in the intent-filter. If you need a wake lock, which you likely don't, then schedule a job from your BroadcastReceiver instead of using a WakefulBroadcastReceiver.
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 have a gcm receiver, but it is not working before restarting phone and after clean memory. What should i change to guarantee receiver is always working?
<activity
android:name="com.example.diyet.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.plugin.gcm" />
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />,
thanks in advance
if u want to start your receiver manually then use
registerReceiver(receiver) inside your activity
Sorry I don't know anything about GCM but if I get you right you have one of the following possibilities
If your GCMIntentService is custom, you can make this Service STICKY So the OS restarts it after a Crash. To do this you have to return return Service.START_STICKY; in your onStartCommand Method.
Also you can Register for the android.intent.action.BOOT_COMPLETED to get your Service started right after device is Booted.
If you want to prevent the Service to Crash, when the App Crashes you have to put it in another Thread. This can be achieved by Setting an custom Process Name in the Manifest
android:process="com.gigatronik.presenter.serialport.SerialPortListenerService"/
I will edit this answer, if you can give me more information on your Problem, since I never used GCM
i want receive all start app intents (i think MAIN/LAUNCHER, see below) to log how often i used the application. So i do not want create an activity... I tried several receiver blocks, but for now nothing works:
with, without priority, only the action, both, only the category and so on..
<receiver android:name=".Receiver" android:enabled="true"
android:process=".e">
<intent-filter priority="100000" android:priority="100000">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
Have anyone an idea?
Thanks
I want receive all start app intents
You cannot do that, sorry.