package cn.com.sms.send;
import java.util.ArrayList;
import java.util.Iterator;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Send extends Activity {
private String message;
private String number ;
private EditText editText;
private EditText editText2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) this.findViewById(R.id.number);
editText2 = (EditText)this.findViewById(R.id.message);
Button button = (Button)this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
number = editText.getText().toString();
message = editText2.getText().toString();
// 在LogCat中可以查看到number和message的相关信息
Log.i("number", number);
Log.i("message", message);
/*获取系统默认的信息管理器,一定要注意的是SmsManager是android.telephony.SmsManager;这和
*我们使用的版本有关,在 Android 2.0 以前 应该使用 android.telephony.gsm.SmsManager
*Android 2.0 之后的版本应该用 android.telephony.SmsManager。
*/
SmsManager smsManager = SmsManager.getDefault();
/*PendingIntent.getBroadcast返回一个用于广播的PendingIntent对象,类似于调用Content.sendBroadcast();
*/
PendingIntent paIntent = PendingIntent.getBroadcast(Send.this, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveryIntent = PendingIntent.getBroadcast(Send.this, 0, new Intent("SMS_DELIVERED"), 0);
// smsManager.divideMessage有些时候短信如果超过了字数,我们就需要这个方法来帮我们拆分短信内容。
ArrayList<String> smses = smsManager.divideMessage(message);
Iterator<String> iterator = smses.iterator();
while(iterator.hasNext()){
String temp = iterator.next();
//发送短信
smsManager.sendTextMessage(number, null, temp, paIntent, deliveryIntent);
}
// 弹出一个浮动框显示提示内容,Toast.LENGTH_LONG代表浮动框显示时间的长短
Toast.makeText(Send.this, "短信发送完成", Toast.LENGTH_LONG).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="欢迎使用短信发送器,请输入电话号码" /> <EditText android:id="@+id/number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="这里输入电话号码" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="欢迎使用短信发送器,请输入短信内容" /> <EditText android:id="@+id/message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minLines="3" android:hint="这里输入短信内容" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="send" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.com.sms.send"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Send"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SmsManager smsManager = SmsManager.getDefault();
SmsManager smsMgr = SmsManager.getDefault(); smsMgr.sendTextMessage(address, null, message, null, null);
Uri smsToUri = Uri.parse("smsto://10086");
Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
startActivity( mIntent );
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, address);
i.putExtra(Intent.EXTRA_SUBJECT, filename);
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filename)); ;
i.setType("text/csv");
startActivity(Intent.createChooser(i, "EMail File"));
package cn.com.sms.send;
import java.util.ArrayList;
import java.util.Iterator;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Send extends Activity {
private String message;
private String number ;
private EditText editText;
private EditText editText2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) this.findViewById(R.id.number);
editText2 = (EditText)this.findViewById(R.id.message);
Button button = (Button)this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
number = editText.getText().toString();
message = editText2.getText().toString();
// 在LogCat中可以查看到number和message的相关信息
Log.i("number", number);
Log.i("message", message);
/*获取系统默认的信息管理器,一定要注意的是SmsManager是android.telephony.SmsManager;这和
*我们使用的版本有关,在 Android 2.0 以前 应该使用 android.telephony.gsm.SmsManager
*Android 2.0 之后的版本应该用 android.telephony.SmsManager。
*/
SmsManager smsManager = SmsManager.getDefault();
/*PendingIntent.getBroadcast返回一个用于广播的PendingIntent对象,类似于调用Content.sendBroadcast();
*/
PendingIntent paIntent = PendingIntent.getBroadcast(Send.this, 0, new Intent("SMS_SENT2"), 0);
PendingIntent deliveryIntent = PendingIntent.getBroadcast(Send.this, 0, new Intent("SMS_DELIVERED2"), 0);
// 注册一个BroadcastReceiver,当有匹配它的IntentFilter的Intent出现时,该方法会被触发
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
int resultCode = getResultCode();
switch(resultCode){
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "信息发送成功了哦、", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(getBaseContext(), "信息发送失败了哦、", Toast.LENGTH_LONG).show();
}
}
}, new IntentFilter("SMS_SENT2"));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getBaseContext(), "deliveryIntent", Toast.LENGTH_LONG).show();
Log.i("短信接收人是否查看信息", "看了");
}
}, new IntentFilter("SMS_DELIVERED2"));
// smsManager.divideMessage有些时候短信如果超过了字数,我们就需要这个方法来帮我们拆分短信内容。
ArrayList<String> smses = smsManager.divideMessage(message);
Iterator<String> iterator = smses.iterator();
while(iterator.hasNext()){
String temp = iterator.next();
//发送短信
smsManager.sendTextMessage(number, null, temp, paIntent, deliveryIntent);
}
// 弹出一个浮动框显示提示内容,Toast.LENGTH_LONG代表浮动框显示时间的长短
Toast.makeText(Send.this, "短信发送完成", Toast.LENGTH_LONG).show();
}
});
}
}
<receiver android:name="类名"> <intent-filter> <action android:name="接收者中Intent参数的action属性" /> </intent-filter> </receiver>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有