Every other question here is about ACTION_CALL or ACTION_DIAL or those topics. I get that. I need an intent. But how do you implement your custom dialer? I've searched and searched and I can't find anything regarding this topic. I have it all designed, ready to go, but nothing on how to put it all together.
I thought it would be as simple as adding some elements and styles to layout/activity_main.java but it isn't. Simple tests so far have just made the app crash on load. Like:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/title_two"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:maxLength="11" >
<requestFocus />
</EditText>
<Button
android:id="@+id/one"
android:text="1" />
<Button
android:id="@+id/two"
android:text="2" />
<Button
android:id="@+id/three"
android:text="3" />
<Button
android:id="@+id/four"
android:text="4" />
<Button
android:id="@+id/five"
android:text="5" />
<Button
android:id="@+id/six"
android:text="6" />
<Button
android:id="@+id/seven"
android:text="7" />
<Button
android:id="@+id/eight"
android:text="8" />
<Button
android:id="@+id/nine"
android:text="9" />
<Button
android:id="@+id/star"
android:text="*" />
<Button
android:id="@+id/zero"
android:text="0" />
<Button
android:id="@+id/pound"
android:text="#" />
<Button
android:id="@+id/callButton"
android:text="Call" />
<Button
android:id="@+id/contacts"
android:text="Con" />
<Button
android:id="@+id/del"
android:text="Del" />
I'm sure that's just some kind easy problem I'm running into but I can't even get any buttons added without crashing everything. Then in src/MainActivity.java:
public class MainActivity extends Activity {
Button dialBtn;
EditText numTxt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialBtn = (Button) findViewById(R.id.button1);
numTxt = (EditText) findViewById(R.id.editText1);
dialBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
if (numTxt != null && (numTxt.getText().length()==10 ||numTxt.getText().length()==11)) {
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel: 8880000000" + numTxt.getText())));
}else if(numTxt != null && numTxt.getText().length()==0){
Toast.makeText(getApplicationContext(), "You must enter a number to call", Toast.LENGTH_SHORT).show();
}else if(numTxt != null && numTxt.getText().length()<10){
Toast.makeText(getApplicationContext(), "Please check your number and try again", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Log.e("DialerActivity", "error: " + e.getMessage(), e);
}
}
});
}
}
The only goal here is to present a dialer to the user. They enter their number, they can see it on the screen like a normal dialer, and then it calls a hardcoded access number for the service, then passes in their dialed number when the eventListener changes to answer.
I will admit I'm new to this so there's a couple of glaring mistakes, I know, I'm just too new to see them. I figured this would be one of the easiest things you could do with Android since there are a million customer dialers out there. I'm not trying to do anything fancy, you have to use the app to use the service, i.e. it's not hanging around in the background with a BroadcastReceiver trying to intercept your outgoing calls and see if you want to use the service. Just a simple dialer app. Where am I going wrong? Some of this code is copied straight from books, online tutorials, just trying to get it to work but a straight copy and paste I can't get working?