📄 receivesms.java~100~
字号:
package keti2;
import java.io.*;
import java.lang.Integer;
import javax.comm.*;
import java.util.*;
import java.util.StringTokenizer;
public class ReceiveSMS extends ATcommand {
protected String sms;
protected String test;
protected static String s1;
protected String Phnum;
protected String chinesesms;
public ReceiveSMS() throws IOException, NoSuchPortException, PortInUseException,
UnsupportedCommOperationException {
}
public String reiceive(int geshu)throws IOException
{
sms=ReadSMS(geshu);
Phnum=phonenumber(sms,geshu);
System.out.print(sms);
/*%%%%%%下面是一次只读一条时,用转换成汉字的程序部分%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
StringTokenizer stringtokenizer=new StringTokenizer(sms);
int i=stringtokenizer.countTokens();
int j=3;
String s4=new String();
String s5=new String();
String s2=new String();
s2 = stringtokenizer.nextToken();
s2 = stringtokenizer.nextToken();
s2 = stringtokenizer.nextToken();
char []cbuffer;
if (i==10)
{
while(stringtokenizer.hasMoreTokens())
{
if (j != i-2 && j < i) {
s2 = stringtokenizer.nextToken();
}
else if (j == i - 2) {
s4 = stringtokenizer.nextToken().trim();
char first;
first = s4.charAt(0);
if (Character.isDigit(first)) {
int k = s4.length() / 4 + 1;
int k2 = 1;
int k3 = 0;
cbuffer = new char[k];
int k1 = 1;
while (k2 < k) {
cbuffer[k1] = (char) Integer.parseInt(s4.substring(k3, k3 + 4),
16);
k3 = k3 + 4;
k2++;
k1++;
}
s4 = new String(cbuffer);
s4 = s4.trim();
}
s1 = s1 + s4;
}
else {
s2 = stringtokenizer.nextToken();
}
s1 = s1 + s2;
j++;
System.out.print("\n");
}//endwhile
}//end if
else
{
while(stringtokenizer.hasMoreTokens())
{
if(j<3)
{
if (j != i-2 && j < i)
{
s2 = stringtokenizer.nextToken();
}
}//endif(j<3)
else if((j>=3)&&(j<=i-2))
{
s4 = stringtokenizer.nextToken();
s5=s5+s4;
}//endelse if((j>=3)&&(j<=i-2))
else
{
s2 = stringtokenizer.nextToken();
}//end else
s1 = s1 + s2;
j++;
s4=s5;
}//endwhile
}//endelse
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
System.out.print("\n");
System.out.print(Phnum);
chinesesms=s4;
return chinesesms;
}//end reiceive()
public String phonenumber(String text,int u)//这是一次只读入一条时的取得号码的方法
{String num=new String();
StringTokenizer stringtokenizer1=new StringTokenizer(text);
int i=stringtokenizer1.countTokens();
String s7=new String();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7 = stringtokenizer1.nextToken();
s7=s7.substring(10,21);
num=s7;
return num;
}
public String CnEnCode(String text,int num)//这是一次读如多条时的汉字处理方法
{
if(num<10)
{
text=text.substring(54);
}
else
{
text=text.substring(55);
}
int l=(text.length()/4)+1;
int k1=1;
int k2=1;
int k3=0;
char []cbuffer=new char[l+1];
System.out.print(text);
while(k2<l)
{
cbuffer[k1] = (char) Integer.parseInt(text.substring(k3, k3 + 4), 16);
k3 = k3 + 4;
k2++;
k1++;
}
cbuffer[l]='\0';
String cn=new String(cbuffer);
cn=cn.trim();
String chinese=cn;
return chinese;
}
public String getphonenum(String text,int num)
{
String phone=new String();
if(num<10)
{
phone=text.substring(18,29);
}
else
{
phone=text.substring(19,30);
}
return phone;
}
}//end class()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -