android third day

What I am doing today is a mobile phone dialing and SMS sending app. I originally wanted to add an email function, but it was unsuccessful, so I will not demonstrate it here-. -

 

The first is the start page of the APP. There are three options, one is dial-up, one is text message, and the other is email, but because the email didn't work, you should ignore it!



 

I will show you one by one now. The first is the dialing part of the phone. After filling in the phone number, you can dial with your heart. The dialer of the system is used. Another function of this interface is to add contacts. You can jump to the interface of the system to add contacts

 

 



 

 

 

main code for dialer

package com.example.bohao;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity {
        private EditText textResult;
        StringBuffer currentNum=new StringBuffer();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView(R.layout.activity_main);
        textResult = (EditText) findViewById (R.id.edittext1);
    }
    public void display(){
    	textResult.setText(currentNum.toString());
    }
public double stringToDouble(){
	if(currentNum.length()==0)
	{
		return 0;
	}
	double result=Double.parseDouble(currentNum.toString());
	return result;
}
public void digital_click(View view)
{
	ImageButton btnDigital=(ImageButton)view;
	String text=btnDigital.getTag().toString();
	currentNum.append(text);
	display();
	}
public void delete(View view)
{
	if(currentNum.length()>=1)
	{
		currentNum.delete(currentNum.length()-1,currentNum.length());
		
	}
	if(currentNum.length()==0)
	{
		Toast toast=Toast.makeText(this,"Please enter the number",100);
		toast.show();
		display();
	}
	textResult.setText(currentNum);
	}
public void dial(View view){
	EditText text=(EditText)findViewById(R.id.edittext1);
	String number=text.getText().toString();
	Intent intent=new Intent();
	intent.setAction(intent.ACTION_CALL);
	intent.setData(Uri.parse("tel:"+number));
	startActivity(intent);
}

public void addContact(View view){  
    Intent it = new Intent(Intent.ACTION_INSERT,Uri.withAppendedPath(Uri.parse("content://com.android.contacts"),"contacts" ));  
    it.setType("vnd.android.cursor.dir/person");  
    String number = textResult.getText().toString();  
    it.putExtra(android.provider.ContactsContract.Intents.Insert.SECONDARY_PHONE,number);  
    startActivity(it);  
      
}  
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

 

 

Next is the SMS function. Needless to say, there is no need to say more about SMS. Here, the source code of the interface is mainly displayed.



 Next is the source code. I originally wanted to get a letter reminder, but it failed again. . . .

package com.example.bohao;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class Message extends Activity {

	private EditText tel;
	private EditText content;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView(R.layout.activity_message);
		tel=(EditText)findViewById(R.id.sjr);
		content=(EditText)findViewById(R.id.nr);
	}
	public void send (View view)
	{
		String telMsg=tel.getText().toString();
		String contentMsg=content.getText().toString();
		
		Uri uri=Uri.parse("smsto:"+telMsg);//Receiver's mobile phone
		Intent it=new Intent();
		it.setAction(Intent.ACTION_SENDTO);
		it.setAction(Intent.ACTION_SENDTO);//Specify action, I want to send text message
		it.putExtra("sms_body", contentMsg);//Set the information content
		it.setType("vnd.android-dir/mms-sms");//Set MIME type
		it.setData(uri);//Set data, where to go
		Message.this.startActivity(it);
		
	}
	//Incoming letter reminder part, failed
	public void show(StringBuffer SMSAddress,StringBuffer SMSContent)
	{
		NotificationManager notificationmanager=(NotificationManager)getSystemService(Activity.NOTIFICATION_SERVICE);
		   Notification notification=new Notification(R.drawable.ic_launcher,SMSAddress,System.currentTimeMillis());
		   PendingIntent contentIntent=PendingIntent.getActivity(this, 0, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
		   notification.setLatestEventInfo(this, SMSAddress, SMSContent, contentIntent);
		   notificationmanager.notify("qq", R.drawable.ic_launcher, notification);  
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.message, menu);
		return true;
	}

}

 

This time the code is relatively simple, and it calls some packaged things, so although it is very convenient to use, it is difficult to understand. Because they are all things that call the system, I will not expand this time. Maybe it is the reason for the failure. QAQ

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263704&siteId=291194637