i have following problem:
i write broadcastReceiver that receive android.intent.action.BOOT_COMPLETED all work fine if i do restart from power options or remove battery, but if i use POWER OFF - power option system did't go thrue BOOT_COMPLETED intent. Please help what kind of intent i must receive to get this to cases for auto startup activity on android phone.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".StartupBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
In your Broadcast Receiver class, Check :
getIntent().getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED") {
// call startActivity(intent);
}
It will definitely help you.
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'm having an app that must run when android system start-up, I used the usual way of registering the broadcast and receiving it:
in manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.automation.isolace"
android:versionCode="8"
android:versionName="1.3"
android:installLocation="internalOnly" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
.
.
.
<receiver
android:name="com.automation.standards.BootCompletedReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter android:priority="999">
<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>
.
.
.
</application>
</manifest>
And in BroadcastReceiver class:
public class BootCompletedReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Log.d("MConn", "BOOT_COMPLETED received");
}
}
then, when the device boots, the app supposed to receive the boot_completed broadcast immediately, but the result varies across different devices, at some devices the app receives it immediately and in others it receives it after a while, this while can be a second or two and at some devices it reaches about 10 seconds, and the problem here is that the app must run before the home screen UI appears, so it has to receive the broadcast immediately.
As appears in the code in manifest, I tried to give the broadcast the most high priority ever, but the issue is still on the table.
So, what are the possibilities that can make this happen, and is there is a way to solve that? and is there is a way to overcome that in a work-around way (like preventing the device from displaying the screen for a while or blocking the system from starting its home activity layout)?
I need my app to be started automatically once after the phone reboot and Power-on.
I used the code provided at AutoStart an Application at boot up and now my android app starts automatically after the phone reboot (restart).
Now, consider that instead of doing a phone reboot, I have used Phone power off (Shut phone down) option. After the phone power on, my app is not started automatically as expected. Can you please explain what I have missed.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:enabled="true" android:name=".BootUpReceiver" 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>
public class BootUpReceiver extends BroadcastReceiver
{
private static SharedPreferences aSharedSettings;
#Override
public void onReceive(Context context, Intent intent)
{
aSharedSettings = context.getSharedPreferences("MYPreferences", Context.MODE_PRIVATE);
boolean isUserLoggedIn = aSharedSettings.getBoolean(kEY.AUTHENTICATED, false);
if(isUserLoggedIn)
{
Intent aServiceIntent = new Intent(context, HomeView.class);
aServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(aServiceIntent);
}
}
}
Thank You.
Does it work as intended if you launch the application manually at least once before rebooting the phone, and not 'Force-close' it?
Have a look at:
Android : android.intent.action.BOOT_COMPLETED on ICS and Gingerbread
Boot Completed Regression Confirmed
There are a few things you can try.
Firstly check that your app installLocation in the AndroidManifest.xml is set to android:installLocation="internalOnly" this makes sure that the app is on the local storage. Apps installed to the sdcard will not receive the BOOT_COMPLETE intent.
Also I would remove <category android:name="android.intent.category.DEFAULT" /> it is not necessary.
And the last thing you can try is using a full package name:
<receiver android:enabled="true"
android:name="com.myapp.receivers.BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Try to add
<category android:name="android.intent.category.LAUNCHER" />
instead of
<category android:name="android.intent.category.DEFAULT" />.
And also check the value of isUserLoggedIn.
Are you using a HTC device? If so, you may have a feature enabled called "Fast-Boot"
See this link for details.
Detect if HTC "Fast boot" is enabled
the name of the Activity from where you are starting your application, Add this line in your tag.....And let me know it worked or not
<category android:name="android.intent.category.HomeView" />
I am trying to stop a BroadcastReceiver from showing up once I exit my application. Until now I only made it show a Toast when an App is installed. It works really well, except that if I exit the app the receiver is still active.
This is my Receiver code from the AndroidManifest:
<receiver android:name=".MyBrowdcastreceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
I want to know what should I put in my onDestroy() or onStop() methods from my main Activity that will cause the receiver to stop.
Thanks.
You have registered the receiver in manifest file which will receive notification even if your app is not running.You can do two things to fulfill your need:
You need to register , unregister the receiver programmatically.
You can take boolean which you will set true if the app is running else false. You can use this boolean on BraodcastReceiver's onReceive() method where you need to put check over the boolean and perform your action if the boolean is true.
LiveWallpapers have the permission BIND_WALLPAPER that allows only the system to bind to it. I want the livewallpaper service to be set as the wallpaper, when the device boots up. For this I have written a broadcast receiver that on boot up is meant to start the wallpaper service, using intents. The component of the livewallpaper is set as the component of the intent. At the moment this can detect the wallpaper service but cannot set it due to the permission BIND_WALLPAPER. The manifest of my application includes as follows
<receiver android:name=".MyStartupIntentReceiver" android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
The broadcast receiver is as follows :
Intent ii = new Intent(Intent.ACTION_MAIN);
ii.addCategory(Intent.CATEGORY_HOME);
ii.setComponent(new ComponentName("com.example.android.livecubes","com.example.android.livecubes.cube1.CubeWallpaper1"));
context.startService(ii);
Ive also tried the above with action.SET_WALLPAPER...category : Launcher/default but everything throws the error permission denied: bind_wallpaper needed. This permission is present at both the service and receiver ends. How can I set the livewallpaper on boot up without chooser/livewallpaper picker ?
This is not possible. You can start the chooser, but you cannot bypass the chooser and actually set the wallpaper in a seamless way. See comment from Romain Guy here: http://groups.google.com/group/android-developers/browse_thread/thread/a22e66002f884718