0
我正在嘗試編程一個Android應用程序,該應用程序使用USSD從手機向我的網絡提供商服務器發送更新。問題是要從網絡服務器獲取數據到我的web服務器,我需要base64編碼數據報中的數據。我試圖發送這個數據的格式是* #其中數據報由這組成。這允許我在單個USSD數據包中發送2個數據報。通過USSD從Android發送Base64編碼的數據
這是我迄今爲止
private void sendUSSDupdate(Integer data1, Integer data2){
char[] data1CharArray = data1.toString().toCharArray();
char[] data2CharArray = data2.toString().toCharArray();
Integer data1Length = data1CharArray.length * 2;
Integer data2Length = data2CharArray.length * 2;
char[] dataDatagram = new String(PID.toString() + data1Length.toString() + new String(data1CharArray)).toCharArray();
char[] dataDatagram = new String(PID.toString() + data2Length.toString() + new String(data2CharArray)).toCharArray();
String ussdAddress = "*126*5*";
byte[] data1ByteArray = new byte[data1Datagram.length * 2];
ByteBuffer.wrap(data1ByteArray).asCharBuffer().put(data1Datagram);
byte[] data2ByteArray = new byte[data2Datagram.length * 2];
ByteBuffer.wrap(data2ByteArray).asCharBuffer().put(data2Datagram);
byte[] base64data1Datagram = Base64.encode(dataByteArray, Base64.NO_PADDING);
byte[] base64data2Datagram = Base64.encode(dataByteArray, Base64.NO_PADDING);
byte[] dat = new byte[base64data1Datagram.length + base64data2Datagram.length];
int i = 0;
while(i < base64data1Datagram.length - 1){
dat[i] = base64data1Datagram[i];
i++;
}
int j = 0;
while(i < dat.length - 1){
dat[i] = base64data2Datagram[j];
i++;
}
try{
Intent ussdIntent = new Intent(Intent.ACTION_CALL);
ussdIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
ussdIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
ussdIntent.setFlags(Intent.FLAG_FROM_BACKGROUND);
Uri uri = Uri.fromParts("tel", ussd + dat, encodedHash);
System.err.println(uri);
ussdIntent.setData(uri);
act.startActivity(ussdIntent);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
而你的問題是......? – CommonsWare