mr droid.
mr droid.

Reputation: 42

using broad cast receiver along with activity

i am working on a project with many activities but when trying to code a broad cast receiver within a class the broadcast receiver is not working though i have given permission to manifest file. with reciver.

<receiver android:name=".IncomingCallReciever" android:exported="true" android:enabled="true">
    <intent-filter android:priority="1">actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" />
        <action android:name="android.intent.action.PHONE_STATE" />
        <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter>
</receiver>

Upvotes: 1

Views: 284

Answers (2)

AbhishekB
AbhishekB

Reputation: 2075

I can't see any mistakes with the XML excerpt that you posted. However, there might be an error in the tag android:name. This should be a fully qualified class name (for example com.example.project.ReportReceiver). However, as a shorthand, if the first character of the name is a period (for example, .ReportReceiver), it is appended to the package name specified in the <manifest> element. Using that shortcut, your package name should be something like package="com.example.project". In your case, you should check the whole package name before .IncomingCallReciever.


EDIT:

Check for problems here particularly:

<intent-filter android:priority="1">
    actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" />

Remove the > after android:priority="1" - that's a syntax problem, it should work once you correct that.

Upvotes: 2

mr droid.
mr droid.

Reputation: 42

public void onReceive(Context context, Intent intent) {
mContext = context;
mIntent = intent;
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
tm.listen(phoneStateListener, events);
}

Upvotes: 0

Related Questions