-2

i have this very basic code that should work as a call application. everything is hardcoded.

i don't find usefull tutorials according to this application i need / want to create.

my question is large ! Can anyone pls help me creating a CallApplication

requirement is simple i think

need to be able to dail a number

this is the code i have at the moment, as said it is very basic, but i'm stuck ^^

any help is much appreciated!

import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    public class MainActivity extends Activity {

        final Context context = this;
        private Button btn;

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            btn = (Button) findViewById(R.id.button);

            PhoneCallListener phoneCallListener = new PhoneCallListener();
            TelephonyManager telManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
            telManager.listen(phoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);

            // add button listener
            btn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {

                    Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
                    phoneCallIntent.setData(Uri.parse("tel:123456"));
                    startActivity(phoneCallIntent);

                }

            });

        }

        // monitor phone call states
        private class PhoneCallListener extends PhoneStateListener {

            String TAG = "LOGGING PHONE CALL";

            private boolean phoneCalling = false;

            @Override
            public void onCallStateChanged(int state, String incomingNumber) {

                if (TelephonyManager.CALL_STATE_RINGING == state) {
                    // phone ringing
                    Log.i(TAG, "RINGING, number: " + incomingNumber);
                }

                if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
                    // active
                    Log.i(TAG, "OFFHOOK");

                    phoneCalling = true;
                }

                // When the call ends launch the main activity again
                if (TelephonyManager.CALL_STATE_IDLE == state) {

                    Log.i(TAG, "IDLE");

                    if (phoneCalling) {

                        Log.i(TAG, "restart app");

                        // restart app
                        Intent i = getBaseContext().getPackageManager()
                                .getLaunchIntentForPackage(
                                        getBaseContext().getPackageName());

                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(i);

                        phoneCalling = false;
                    }

                }
            }
        }

    }
SeeSharp
  • 93
  • 2
  • 3
  • 6
  • as you at some point in the code... i got a contact hardcoded. ---phoneCallIntent.setData(Uri.parse("tel:123456"));--- this has to get dynamic... by this i mean ... instead of hardcoded... i need to be able to dail a number and call the number i've dailed ... you see ? xD ... – SeeSharp Mar 26 '14 at 10:07

1 Answers1

1

As per @SeeSharp comment.

I guess your requirement is to remove hardcoded contact.

Way 1:

Take contact as Input from User (Example in EditText , Design UI).

Way 2:

Use Getting a Result from an Activity to get contact from Contacts App.

startActivityForResult() Contacts Application to Pick a contact from android.provider.ContactsContract. More at : this and this.

Read ContactsContract.


Note : Please make your problem/Issue in question explanatory enough to be understood.

Hope this helps !!

Community
  • 1
  • 1
Aduait Pokhriyal
  • 1,529
  • 14
  • 30
  • Hmmm not really , perhaps anyone who wants to hold my ahdn and get me a full explenation... -- Perhaps his own code or way of programming ?-- it's been almost a week and i stil haven't figured it out. Who has an example for an application(custom) which alows me to dail a number and call that number in real life ? pls .. much appriciated – SeeSharp Mar 28 '14 at 09:06