package gr.mybook.mybroadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class Activity_2 extends BroadcastReceiver {
	private static final String TAG = "Activity_2";
 
    @Override
    public void onReceive(Context context, Intent intent) {
    	Bundle extras = intent.getExtras();
    	String action=intent.getAction();
    	if (action.equals("gr.mybook.mybroadcastintent")) {
    		Toast.makeText(context, "BROADCAST INTENT OF ACTIVITY 1", Toast.LENGTH_LONG).show();
    	}
    	if (action.equals("android.intent.action.PHONE_STATE")) {
    		Toast.makeText(context, "RINGING", Toast.LENGTH_LONG).show();
    		Log.w(TAG, "RINGING");
    		String state = extras.getString(TelephonyManager.EXTRA_STATE);
		    Log.w(TAG, state);
		    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
		      String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
		      Log.w(TAG, phoneNumber);
		    }
    	}
    }
}