Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:00:36+00:00 2026-06-07T06:00:36+00:00

public void onCallStateChanged(int state,String incomingNumber) { System.out.print(\nState :- +state); switch(state){ case TelephonyManager.CALL_STATE_IDLE: if(flag==true &&

  • 0
 public void onCallStateChanged(int state,String incomingNumber)
{
    System.out.print("\nState :-  "+state);
      switch(state){
        case TelephonyManager.CALL_STATE_IDLE:

            if(flag==true && ringflag == true)
            {
                flag=false;
                ringflag=false;
                System.out.print("\nflag = " + flag);
                System.out.print("\nringflag = " + ringflag);
                stop = System.currentTimeMillis();
                System.out.println("\nTotal time : " +stop);
                System.out.println("\nTotal time : " +(stop - start)/1000);
                System.out.println("\nIDLE : " + incomingNumber);
                long time = (stop - start) / 1000;
                String path = Environment.getExternalStorageDirectory().getAbsolutePath();
                f = new File(path + "/sms.txt");
                if (f.exists()) {
                    try {
                        raf =new RandomAccessFile(f, "rw");
                        long pointer = raf.length();
                        raf.seek(pointer);
                        String data = ":-"+no+","+time;
                        raf.writeBytes(data);
                        raf.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                } else {
                    try {
                        raf = new RandomAccessFile(f,"rw");
                        String data = ":-"+no+","+time;
                        raf.writeBytes(data);
                        raf.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            if(ringflag == true)
            {
                System.out.println("OFFHOOK :- " + incomingNumber);
                start = System.currentTimeMillis();
                System.out.print("\nStart is :-" + start);
                flag=true;
            }
        break;
        case TelephonyManager.CALL_STATE_RINGING:
            no = incomingNumber;
            System.out.println("Ringing : " + incomingNumber);
            ringflag= true;
        break;
      }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:00:37+00:00Added an answer on June 7, 2026 at 6:00 am

    I can answer the first part of your question

    To get the call duration it is important to access the Call Logs.

    Using the information given in CallLog.Calls, It can be done like below:

              Uri allCalls = Uri.parse("content://call_log/calls");
              Cursor c = managedQuery(allCalls, null, null, null, null);
                for(String colName : c.getColumnNames())
                    Log.v(TAG, "Column Name: " + colName);
    
                if (c.moveToFirst())
                {
                   do{
                       String id = c.getString(c.getColumnIndex(CallLog.Calls._ID));
                       String num = c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));
                       int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));
    
                       String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));
                       System.out.println("call time duration is"+duration);
    
                        switch (type)
                        {
                            case 1: Log.v(TAG, id + ", " +num + ": INCOMING") ; break;
                            case 2: Log.v(TAG, id + ", " +num + ": OUTGOING") ;break;
                            case 3: Log.v(TAG, id + ", " +num + ": MISSED") ; break;
                        }
                   } while (c.moveToNext());
                }
    

    Refer this nice blog post for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Source: listener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) {
public void Find() { String Value = ; System.out.println(Search Name); Value = Input.next(); int
public void thisisnotworking() { Scanner input=new Scanner(System.in); String cardA; String cardB; System.out.print(Enter Card: );
public void printList( ){ Node<E> p ; System.out.printf( [ ) ; for ( p=head.next
public void onClick(View v) { switch(v.getId()){ case R.id.save2: s = text.getText().toString(); number = Float.parseFloat(num.getText().toString());
public void onClick(View v) { switch(v.getId()){ case R.id.save2: s = text.getText().toString(); number = Float.parseFloat(num.getText().toString());
public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); switch (reqCode)
public void init() { String download = getParameter(update); String home = System.getProperty(user.home); String saveTo
public void CreateVirtualDirectory(string nameDirectory, string realPath) { System.DirectoryServices.DirectoryEntry oDE; System.DirectoryServices.DirectoryEntries oDC; System.DirectoryServices.DirectoryEntry oVirDir; try
public void correctLetter(String Letter, int pos){ if(letter.equals(a)){ ImageView image = images[pos]; image.setImageResource(R.drawable.a); image.setVisibility(ImageView.VISIBLE); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.