如题,,具体问题是这样,在WEB端,编辑一条短信,然后利用手机发送出去..哪位大侠有此类经验,忘指教,,我把分全给了...
解决方案 »
- ubuntu编译源码问题
- android视频播放
- android双卡机apn拨号问题
- 我的电脑连上Adroid手机后logcat中不断的显示“Camera version is not ready”
- Android的openGL编程中的事件监听问题。
- 关于数据存储的问题请教
- 求一个相当于淘宝的Android客服端Activity界面布局
- 淘宝订单有没有接口进行支付的?
- RecyclerView Adapter 使用不同Context创建LayoutInflate有什么区别?
- 不显示的Fragment不能刷新界面
- 求教,如何实现一个类似于Timepicker控件的东西,要求能实现秒的选择,请大侠指点
- 修改default_workplace.xml后桌面无改变的问题
下载
package happly.util;import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;public class HttpDownloader {
public URL url=null;
public String download(String urlstr){
StringBuffer sb=new StringBuffer();
InputStream in = null;
try{
//得到URL
url = new URL(urlstr);
//得到HTTPURL资源
HttpURLConnection hc = (HttpURLConnection)url.openConnection();
//得到输入流
in= hc.getInputStream();
//使用InputStream的anailalble方法得到输入流的字节数
int n=in.available();
//声明一个字节数组
byte[] buf=new byte[n];
while(in.read(buf)!=-1){
//转换字符编码
String str=new String(buf,"GB2312");
// String str=new String(buf);
sb.append(str);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try{
in.close();
}
catch(Exception e){
e.printStackTrace();
}
}
//返回字符串并过滤'\r'
return sb.toString().replace("\r\n", "\n");
}
}
发送:
package happly.main;import happly.main.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;public class SendSms extends Activity {
String str="abd";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_sms);
Intent intent=getIntent();
str=intent.getStringExtra("one").toString();
System.out.println(str);
final EditText smsNum=(EditText)findViewById(R.id.sms_num_id);
final EditText smsText=(EditText)findViewById(R.id.sms_text_id);
smsText.setText(str);
Button smsSend=(Button)findViewById(R.id.sms_send_id);
smsSend.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String phoneNum=smsNum.getText().toString();
//String phoneText=smsText.getText().toString();
// smsText.setText("abc");
String phoneText=smsText.getText().toString();
if(phoneNum.length()>0&&phoneText.length()>0){
sendSMS(phoneNum,phoneText);
}
else {
Toast.makeText(SendSms.this,R.string.error,Toast.LENGTH_LONG).show();
}
} private void sendSMS(String phoneNumber, String Massage) {
// TODO Auto-generated method stub
//PendingIntent pi = PendingIntent.getActivity(SendSms.this,0,new Intent(SendSms.this,SendSms.class),0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null,Massage,null,null);
Toast.makeText(SendSms.this, R.string.succeed,Toast.LENGTH_SHORT).show();
SendSms.this.finish();
}
});
}
}