hello friends i am working on android broadcast receiver but it is not working. My code for broadcast receiver is given below.
public class MainActivity extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1){
Toast.makeText(arg0, "Service Explicitely", Toast.LENGTH_SHORT).show();
arg0.stopService(new Intent(arg0,CallRecordingService.class));
Intent intent=new Intent(arg0, CallRecordingService.class);
arg0.startService(intent);
Toast.makeText(arg0, "Service Explicitely", Toast.LENGTH_SHORT).show();
}
and the manifiest file is also given
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>
<service android:name=".CallRecordingService" />
</application>
please solve the problem.
Try this code. Sure it will help for you. Its working fine for me.