打电话发短信
代码
package org.jgw.hello;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.telephony.SmsManager;
import android.view.*;
public class HellowordActivity extends Activity {
/** Called when the activity is first created. */
EditText mobel;
EditText SMS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mobel=(EditText) findViewById(R.id.editText1);
Button button1=(Button)this.findViewById(R.id.button1);
button1.setOnClickListener(new ButtonClickListener());
SMS=(EditText) findViewById(R.id.editText2);
Button sendSMS=(Button) findViewById(R.id.button2);
sendSMS.setOnClickListener(new SendSMS());
}
private final class SendSMS implements View.OnClickListener
{
public void onClick(View v) {
String ls_number=mobel.getText().toString();
String ls_content=SMS.getText().toString();
SmsManager manager=SmsManager.getDefault();
ArrayList<String> texts=manager.divideMessage(ls_content);
for(String text:texts)
{
manager.sendTextMessage(ls_number, null, text, null, null);
}
Toast.makeText(HellowordActivity.this, R.string.sendsuccess, Toast.LENGTH_LONG).show();
}
}
//打电话
private final class ButtonClickListener implements View.OnClickListener
{
public void onClick(View v) {
String ls_number=mobel.getText().toString();
Intent intent=new Intent();
intent.setAction("android.intent.action.CALL");
//intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("tel:"+ls_number));
startActivity(intent);//把意图传给操作系统
}
}
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.telephony.SmsManager;
import android.view.*;
public class HellowordActivity extends Activity {
/** Called when the activity is first created. */
EditText mobel;
EditText SMS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mobel=(EditText) findViewById(R.id.editText1);
Button button1=(Button)this.findViewById(R.id.button1);
button1.setOnClickListener(new ButtonClickListener());
SMS=(EditText) findViewById(R.id.editText2);
Button sendSMS=(Button) findViewById(R.id.button2);
sendSMS.setOnClickListener(new SendSMS());
}
private final class SendSMS implements View.OnClickListener
{
public void onClick(View v) {
String ls_number=mobel.getText().toString();
String ls_content=SMS.getText().toString();
SmsManager manager=SmsManager.getDefault();
ArrayList<String> texts=manager.divideMessage(ls_content);
for(String text:texts)
{
manager.sendTextMessage(ls_number, null, text, null, null);
}
Toast.makeText(HellowordActivity.this, R.string.sendsuccess, Toast.LENGTH_LONG).show();
}
}
//打电话
private final class ButtonClickListener implements View.OnClickListener
{
public void onClick(View v) {
String ls_number=mobel.getText().toString();
Intent intent=new Intent();
intent.setAction("android.intent.action.CALL");
//intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("tel:"+ls_number));
startActivity(intent);//把意图传给操作系统
}
}
}
mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jgw.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".HellowordActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jgw.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".HellowordActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>