BootCompleted Receiver not running - android

Hello I am new android developer. I create a sample project that works well when boot is completed.
Then I again create my main project to use this but boot completed not executed... I try my best to find problem.. I register this receiver through Manifest file not pragmatically...
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Toast.makeText(context, "boot completed", Toast.LENGTH_LONG).show();
//throw new UnsupportedOperationException("Not yet implemented");
}
and is Manifest XML
<receiver
android:name="com.azmizryk.mobilethefttracker.BootCompleted"
android:enabled="true"
android:exported="true" >
</receiver>

Add following Intent actions in manifest.xml file.
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
i.e. in your manifest file,change
<receiver
android:name="com.azmizryk.mobilethefttracker.BootCompleted"
android:enabled="true"
android:exported="true" >
</receiver>
to
<receiver
android:name="com.azmizryk.mobilethefttracker.BootCompleted"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

Related

I am unable to see a toast message for any of the conditions that I've specifed in my broadcast receiver

I have specified all the actions in my manifest.xml file. I am trying to catch them in my Broadcast receiver onReceive but I'm unable to see them.
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
Toast.makeText(context,"Sample broadcast receiver boot completed",Toast.LENGTH_LONG).show();
}
if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())){
Toast.makeText(context,"power connected",Toast.LENGTH_LONG).show();
}
if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())){
Toast.makeText(context,"power disconnected",Toast.LENGTH_LONG).show();
}
}
<receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
In order to receive a BOOT_COMPLETED intent in your application you should add this permission to your AndroidManifest.xml :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
As described in Android SDK's documentation:
If you don't request this permission, you will not receive the broadcast at that time.
You can learn more about that permission here: android.permission.RECEIVE_BOOT_COMPLETED

In android can multiple receiver be called on BOOT COMPLETED?

I have in my manifest 2 recievers on BOOT COMPLETED. one is for location and the other is a generic one which wakes up my service activity . But I noticed when the boot is completed it is not called.
I added //if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {} but it did not help
In manifest I have it as follows:
<receiver android:name=".receiver.MyBootUpReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".helper.MyLocationReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
and My recievers are as follows:
public class MyBootUpReceiver extends BroadcastReceiver {
Context ctx;
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG,"Receiver called..");
}
}
one BroadcaseReceiver is enough, you don't need two separate receivers for same event
add android:enabled="true" to your receiver in manifest file
<receiver
android:name="DeviceBootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

(Android) Subclass of ParsePushBroadcastReceiver doesn't get called on push notification. (parse.com)

I'm attempting to override the default behaviour of the receipt of push notifications from Parse.com's API on the android platform. As per various posts on SO, and in Parse's documentation - I've created the following class:
public class HHPBroadcastReceiver extends ParsePushBroadcastReceiver {
protected void onPushReceive(Context context,
Intent intent){
Log.d("DMM", "onPushReceive");
}
protected void onPushOpen(Context context, Intent intent) {
Log.d("DMM", "onPushOpen");
}
}
In my manifest, I'm also overriding the receiver as follows:
<!-- <receiver
android:name="com.parse.ParseBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver> -->
<receiver
android:name="com.dreamr.hothalls.HHPBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Upon receipt of a push notification, my Receiver doesn't seem to get called - A notification appears in the notification area and clicking this carries out the default action. Nowhere in Logcat does my debug message appear.
I'm at my wit's end trying to work out what is most likely something incredibly simple I've overlooked.
Any advice or suggestions would be much appreciated,
Cheers,
Sean
You must register GCM broadcast receiver as well
<receiver
android:name="com.parse.GcmBroadcastReceiver"
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="us.anyadir.admissiontable" />
</intent-filter>
</receiver>

Service not starting at reboot

I'm trying start a service at the time of booting the device. I have searched many all over and followed the steps and it is still not working out. Once the mobile reboots it shows in the beginning that "application has stopped unexpectedly". I know it is from the receiver file, but couldn't figure out where particularly the problem is.
Receiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Receiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
if(arg1.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent myIntent = new Intent();
myIntent.setAction("com.androidhive.jsonparsing.UpdateService");
context.startService(myIntent);
}
}
}
AndroidManifest
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".AndroidJSONParsingActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Single List Item View -->
<activity
android:label="Single Menu Item"
android:name=".SingleMenuItemActivity" >
</activity>
<service android:name=".UpdateService">
<intent-filter>
<action android:name="com.androidhive.jsonparsing.UpdateService"/>
</intent-filter>
</service>
<receiver android:name=".MyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
Is there anything I need to add so that the service starts perfectly.
Please check you android manifest it should be like this :
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".AndroidJSONParsingActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Single List Item View -->
<activity
android:label="Single Menu Item"
android:name=".SingleMenuItemActivity" >
</activity>
<service android:name=".UpdateService">
<intent-filter>
<action android:name="com.androidhive.jsonparsing.UpdateService"/>
</intent-filter>
</service>
<receiver android:name=".Receiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
The problem is in declaration of your receiver.
Please check the android:name tag, it should have the right class name.
declare your receiver in AndroidManifest.xml as:
<receiver android:name=".Receiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
because you have BroadcastReceiver class as Receiver.class but declaring it in AndroidManifest.xml with MyReceiver
Instead of using
Intent myIntent = new Intent();
myIntent.setAction("com.androidhive.jsonparsing.UpdateService");
context.startService(myIntent);
Try doing this instead in the receiver
Intent myIntent = new Intent(context, UpdateService.class);
context.startService(myIntent);

Can't receive broadcasts for PACKAGE intents

I am trying to register a Broadcast Receiver to receive broadcast events for the package events. Following is the code and my receiver in the manifest file. The log statment never happens, but I can clearly see the same broadcast firing for "HomeLoaders" (the Launcher) debug statements. What am I missing?
public class IntentListener extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("INTENT LISTNER:", intent.getAction());
}
}
<receiver android:name="IntentListener" android:enabled="true" android:exported="true">
<intent-filter>
<data android:scheme="package"></data>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_CHANGED"></action>
</intent-filter>
</receiver>
It is possible that these Intents cannot be received by components registered in the manifest, but only by receivers registered in Java via registerReceiver().
These three intents namely,
Intent.ACTION_PACKAGE_ADDED
Intent.ACTION_PACKAGE_REMOVED
Intent.ACTION_PACKAGE_CHANGED
when broadcasted by the system, have
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
flag added so that only the registered receivers will receive the broadcasts and no broadcast receiver components will be launched. Refer Intent and PackageManagerService class of source for further details.
This is my manifest, without
<category android:name="android.intent.category.DEFAULT" />
My app detects only the Android Market app install, but does not remove. Now it receives also the non-Android Market app broadcasts.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".SomeActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.som.pakage.PackageInstallReceiver" >
<intent-filter >
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>

Categories

Resources