Broadcast Receiver

By | September 16th 2019 10:23:10 PM | viewed 216 times

create a Broadcastphoneactivity activity to get broadcast response

package com.uk.modak;

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

public class Broadcastphoneactivity extends BroadcastReceiver {


    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "UKBroadcast", Toast.LENGTH_LONG).show();
    }
}

to get menifeast and setup broadcast that we use

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".ProjectonOverallClassMainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
        <receiver android:name=".Broadcastphoneactivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE">
            </intent-filter>
        </receiver>
        
    </application>
	 <uses-permission android:name="android.permission.READ_PHONE_STATE" >

to permission for call from handset

bONEandALL