Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boot Receiver not working

Manifest:

         <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".AlarmActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                </intent-filter>
            </activity>
            <receiver android:name="CallReciver">
                <intent-filter>
                    <action android:name="android.intent.action.PHONE_STATE">  

</action>
                </intent-filter>
            </receiver>
            <receiver android:name=".SmsReceiver"> 
               <intent-filter android:priority="1000">
                    <action android:name=
                        "android.provider.Telephony.SMS_RECEIVED" /> 
                </intent-filter> 
            </receiver>
             <receiver android:name=".OnBootReceiver">
          <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
          </intent-filter>
        </receiver>
            <service
                android:enabled="true"
                android:name=".AlarmService">
            </service>
        </application>
         <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
         </uses-permission>
        <uses-permission android:name="android.permission.READ_PHONE_STATE">
        </uses-permission>
        <uses-permission android:name="android.permission.WRITE_SMS">
        </uses-permission>
       <uses-permission android:name="android.permission.READ_SMS">
        </uses-permission>
       <uses-permission android:name="android.permission.SEND_SMS">
        </uses-permission>
        <uses-permission android:name="android.permission.RECEIVE_SMS">
        </uses-permission>
        <uses-permission android:name="android.permission.INTERNET">
        </uses-permission>

Receiver:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class OnBootReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d("Test","booot");
        Toast.makeText(context, "Test", Toast.LENGTH_LONG).show();
    }
}

Receiver doesn't work. I turn off and on my device and nothing happens. SMS And Call Receiver in this project work good. SMS Receiver and CallReceviver - works good. First post updated - added full manifest.

like image 919
user1021984 Avatar asked Nov 02 '11 09:11

user1021984


People also ask

What is boot receiver?

Class BootReceiverImplements a BroadcastReceiver for BOOT_COMPLETED for enabling location monitoring when the device starts if and only if location monitoring was enabled when the device powered off.

What is Receive boot completed?

When Android is booting ( Or you powered ON android first time or rebooted ), and when it has completed booting, Android sends a broadcast intent BOOT_COMPLETED to let all the applications, services know that now everything is setup and android booting has been completed, so we can start any other services , ...

What is the use of broadcast receiver in android?

Android BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.


2 Answers

If you have HTC device you also need to register for "android.intent.action.QUICKBOOT_POWERON". So the entry in manifest should be:

    <receiver android:name=".OnBootReceiver"> 
        <intent-filter> 
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter> 
    </receiver>    

On my HTC, if I turn off the device and turn it on for a while I got QUICKBOOT_POWERON and no BOOT_COMPLETED.

If I turn off the device and remove the battery for a while - I got BOOT_COMPLETED after start.

like image 111
Remi Avatar answered Nov 05 '22 03:11

Remi


Put permission

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
like image 40
Rasel Avatar answered Nov 05 '22 02:11

Rasel