Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InCallLogger extends BroadcastReceiver {
- Context ctx;
- String number;
- @Override
- public void onReceive(final Context context, Intent intent) {
- ctx = context;
- Bundle extras = intent.getExtras();
- if (extras == null)
- return;
- String state = extras.getString(TelephonyManager.EXTRA_STATE);
- if (state == null)
- return;
- gps = new Gpsadd(context);
- // ringing
- if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
- timeStarted = System.currentTimeMillis();
- number = extras
- .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
- number = number.toString().replaceAll("\+", "");
- // System.out.println("From mesages::" + message);
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- simNumber = tm.getLine1Number();
- isRoaming = tm.isNetworkRoaming();
- System.out.println("incoming call broadcast ringing");
- return;
- }
- // answered
- if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)
- && timeStarted != -1L) {
- return;
- }
- // ended
- if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)
- && timeStarted != -1L) {
- return;
- }
- }
- <uses-permission android:name="android.permission.CALL_PHONE" />
- <receiver android:name="incoming.InCallLogger" >
- <intent-filter>
- <action android:name="android.intent.action.PHONE_STATE" />
- </intent-filter>
- </receiver>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement