4

I have implemented Broadcast Receiver in a library project for checking the Boot Completed event , but it is not working.

Broadcast Receiver Class :

public class Reciever  extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent) 
    {
       if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
       {
            Toast.makeText(context, "Device Boot Completed", Toast.LENGTH_LONG).show();
       }
    }
}

AndroidManifest.xml :

    <receiver
        android:name=".Reciever"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

I implemented same Receiver in another application (not library project) and it is working fine.

Hammad Shahid
  • 2,216
  • 5
  • 32
  • 60

4 Answers4

1

BroadcastReceiver cannot be defined in the library project's manifest. The hosting project always needs to declare the components.

android library project and Activities

Edit: I feel this should work with latest Android studio/ gradle based projects.

Community
  • 1
  • 1
jaga
  • 753
  • 11
  • 18
0

You might skipped

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

In manifest file

krish
  • 537
  • 2
  • 14
0

Override the following method

@Override public void onReceive(Context context, Intent intent)

Herojit
  • 32
  • 3
-1

You should add receive tag and reboot permissions to client application manifest file which using your library jar

Like this;

     <receiver android:name="com.example.library.ReceiverClass"
         <intent-filter>
             <action android:name="android.intent.action.BOOT_COMPLETED" />
         </intent-filter>           
     </receiver>
Serkan
  • 641
  • 3
  • 11
  • 19