Does anyone know how K9 Mail's REFRESH_OBSERVER should work? I tried the following as test, but I'm not getting a broadcast when I read/unread/delete/receive:
Manifest:
<receiver android:name=".Monitor">
<intent-filter>
<action android:name="com.fsck.k9.intent.action.REFRESH_OBSERVER"/>
</intent-filter>
</receiver>
...
</application>
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" />
I also tried scheme=email with REFRESH_OBSERVER, but it didn't work.
Monitor.java:
public class Monitor extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("test", "onReceive()");
}
}
On the other hand, the following works:
<intent-filter>
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
<action android:name="com.fsck.k9.intent.action.EMAIL_DELETED" />
<data android:scheme="email" />
</intent-filter>
But I would really like to get a broadcast when messages are read (for counting unread messages) and these two are insufficient for that.
Thanks!
REFRESH_OBSERVER is used only in src/com/fsck/k9/K9.java as part of the MessagingListener method searchStats(), to "let observers know a fetch occurred". It's only called when using the local search feature. Feel free to submit a patch to us if you wish to add some functionality to K-9. See https://github.com/k9mail/k-9/wiki
Related
I am currently working on a reminder app and the BootReceiver is not executed when the Huawei device is rebooted. I have tested the app in other android devices and it works perfectly, except for Huawei specific devices. I have tried the following.
Manifest file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<receiver
android:name=".BootService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.REBOOT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
BootService class
public class BootService extends BroadcastReceiver {
private static final String TAG = "BootService Lumea";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Boot Completed Received: " + intent);
Toast.makeText(context, "Boot Completed Received", Toast.LENGTH_SHORT).show();
}
}
Would be really helpful if you guys can help me find a solution for the same.
There is no doubt that there is a system broadcast in the behavior of power on. The idea is that we can register a broadcast in our code, and it's basically a static broadcast to do this. Here's a sample code. Let's inherit a broadcastreceiver and find a fixed action, that is, get the android.intent.action .BOOT_ Completed, make a logical judgment in it.
Here is skill link
https://blog.csdn.net/u011174639/article/details/106120684?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-1
I'm trying to reset alarms in my app and using a receiver to get onBootCompleted. To see if the intent was received, I'm using a toast. The toast only appears if I immediately open the app. Otherwise, the toast does not appear. I looked at previous questions but almost all of them involve services, which I am not using. I am not sure if that is a part of the problem.
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="internalOnly"
package="package.name" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:configChanges="orientation|screenSize|keyboardHidden"
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver" >
<intent-filter>
<action android:name="android.intent.action.ALARM_SERVICE" />
</intent-filter>
</receiver>
<receiver android:name=".AlarmReset"android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
Receiver Class
public class AlarmReset extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Hello! Got message",
Toast.LENGTH_LONG).show();
//reset alarms etc. No service set.
}
I also tried writing the manifest receiver as
<receiver android:name=".AlarmReset" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Key points I found online were to include permissions (which I did) and to watch out for logging.
What I do not understand is why it works if I immediately (within a few seconds, otherwise the toast does not appear) start my activity but is unsuccessful otherwise. I am considering testing a few possibilities like launching the activity itself through code or using a service like most others have. I am currently testing on Android 4.4 on an actual phone.
When an app is installed, it is in a stopped state. None of its components will be activated (such as your BOOT_COMPLETED receiver) until the app is moved out of this state by being launched by the user. This is why your app doesn't work unless you launch it once.
Note that force stopping the app from Settings also moves it into this stopped state.
See this page for more details (search the page for "launch controls").
Starting with Android 3.1 all applications, upon installation, are placed in a "stopped" state.(This is the same state that the application ends up in after the user force-stops the app from the Settings application.)
While in "stopped" state, the application will not run for any reason, except by a manual launch of an activity. (Meaning no BroadcastReceviers(ACTION_PACKAGE_INSTALLED, BOOT_COMPLETED etc.) will be invoked, regardless of the event for which they have registered, until the user runs the app manually.)
But you can start a serivice for ex-
1) In your element:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2) In your element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver):
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
In MyBroadcastReceiver.java:
package com.example;
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, MyService.class);
context.startService(startServiceIntent);
}
}
I feel the need to clarify the issue and solution, since the question was not clear (due to confidentiality issues).
The Basic Solution to my problem was just starting a service.
The Problem: I was trying to make the alarm in my class, AlarmReset, through AlarmManager. That in itself may have been an issue, but in addition, I tried to access objects that were instantiated in the MainActivity, furthering my dilemma. The reason why it worked when I opened MainActivity quickly enough, I suspect, is because I was able to instantiate the objects and set up the prerequisites for the class to directly access. I think the toast not appearing is similar to the issue.
The Solution: I set up a service class which I directed AlarmReset to. This is what I changed the AlarmReset class to:
public class AlarmReset extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Hello! Got message",
Toast.LENGTH_LONG).show();
//Pretty sure the Toast doesn't appear still.
Intent service = new Intent(context, Service.class);
context.startService(service);
}
Then my service class
public class Service extends IntentService {
private DataBaseManager database;
public Service()
{
super("Service");
}
#Override
protected void onHandleIntent(Intent intent)
{
database = new DataBaseManager(this);
Toast.makeText(this, "Hi",
Toast.LENGTH_LONG).show();
Toast.makeText(this, "Hello! Got message",
Toast.LENGTH_LONG).show();
//rest of code
}
Similarly, the text does not appear except if I am on the app immediately (I suspect it has to do with the threads).
Here, I made sure to instantiate my objects before using them (or did so after crashing).
A few possible problems that others may encounter (as I have read) are the following:
Installing in internal storage
android:installLocation="internalOnly"
and receiving permission for booting
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Some problems that people had suggested and were not very important were:
Using android:enabled and android:exported. Default values are fine
Writing the full receiver name. For me it wasn't necessary
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> did not seem to do much.
I am developing an app which needs a broadcast when app opens every time. I had registered the receiver in manifest like this.
<receiver android:name="package.broadcast.example" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
But i cant able to receive the broadcast. I spent 3 hours on this still i cant find wats the mistake. Can anyone refer me the working example of this broadcast. Thanks.
Restarted Application/Package does not receive broadcast...
check the following link for details
you can check this link
http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_RESTARTED
do u have the following code which extends BroadcastReceiver, if not than try the following code:
public class AutoConnection extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ((intent.getAction() != null)
&& (intent.getAction()
.equals("android.intent.action.PACKAGE_RESTARTED"))) {
Toast.makeText(context, "Pacakge Restarted",
Toast.LENGTH_LONG).show();
}
}
}
and in android manifest file add the following code:
<receiver android:name=".AutoConnection" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
I have implement a feature that will update the database when needed.
(ex. change one of the column value of the database to B)
If system crash or reboot or something that is out of order,
is there any thing I can know then I can handle to recover the database back?
(ex. recover one of the column value of the database back to A)
Thanks for help.
<uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED” />
Define BroadcastReceiver which does the actions you want.
You will need in your manifest sth like:
<receiver android:name=”.MyReceiver”>
<intent-filter>
<action android:name=”android.intent.action.BOOT_COMPLETED” />
</intent-filter>
</receiver>
A crash, by definition, can't be caught.
That's what makes a crash a crash.
When device completes, it Broadcasts a intent and by registering to this broadcast u can get the call:
public class YourReceiverName extends BroadcastReceiver{
#Override
public void onReceive(final Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
//Do your task here....
}
}
}
add permission to manifest file:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and register this receiver in manifest file:
<receiver android:name="Your receiver name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
and for Database, it is upto you how you handle it and what your app demands.
I am new to android. I get completely stuck in using ACTION_PACKAGE_RESTARTED in my application
I have removed pacakge from my emulator, also added using adb install but get nothing. Start an app. close that one and again start that app. nothing seems work for me. There is no log in logcat.
Is there anything that i'm missing? Please help
public class RestartReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action= intent.getAction();
Log.i("D", "Inside receiver");
}
And here is the manifest file
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".ReceiverTest">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.ACTION_PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
</application>
the value specified in the intent filter is incorrect..actual value is
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
and this broadcast can be received for other packages only. Restarted application/package doesn't receive this broadcast.
You should add a data specification to the intent-filter:
<data android:scheme="package" />