How to declare an intent-filter for a Receiver cla

2019-07-30 23:43发布

问题:

I've created a library one of whose class is

public class SmsReceiver extends BroadcastReceiver{...}

Now since this class extends BroadcaseReceiver so I need to declare intent-filter like this:

<receiver android:name="SmsReceiver">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

But, now since the SmsReceiver class is a part of external library so, if I declare the intent-filter like above in the application (application package is com.abc.test) where I'm using the SmsReceiver class, I get an error in the AndroidManifest.xml which says

Class com.abc.test.SmsReceiver doesn't exist

What I need to do to get it working? The library has been included in the project build path and I'm able to call the SmsReceiver class from the app (com.abc.test). The only problem is that the BroadcastReceiver (our SmsReciever class) won't work.

回答1:

Use android:name="the.fully.qualified.class.name.SmsReceiver", where the.fully.qualified.class.name.SmsReceiver is the fully-qualified class name of the SmsReceiver class.