Class 0 SMS (flash SMS) on Android - android
As I know that Nokia and some others phone (like iPhone) are able to sent and receive class 0 SMS , is it possible for android ? Do Android have the API?
What is flash SMS?
Flash SMS is an SMS which is displayed on the phone screen immediately upon arrival.
Unless you choose to save the flash message, it will disappear upon navigating away and will not be saved in your inbox.
If several flash messages are sent to one phone, only the latest message will be displayed, and all the previous ones will be overwritten.
Class 0: Indicates that this message is to be displayed on the MS immediately and a message delivery report is to be sent back to the SC. The message does not have to be saved in the MS or on the SIM card (unless selected to do so by the mobile user).
For rooted Android it is possible to bypass an API and send Class 0 SMS. There is a project on Git Hub called ZeroSMS:
ZeroSMS is a proof-of-concept demonstrating a way to send Class 0 SMS on android >=2.3.
Note: this only works on versions 2.2 -> 4.1.2, the sendRawPdu method was removed, so you will need to find a new way to do this.
It was possible to send Flash SMS (that's the term for class 0 SMS) before Android 2.2.
Google removed the sendRawPdu API, so even if you used reflection, you wouldn't be able to do it.
Here's how I did it previously (this was tested on Android 1.6 and worked)
private void sendSms(String phone, String sms) {
if ((phone == null) || (sms == null) || (phone.length() == 0)
|| (sms.length() == 0)) {
String message = "Phone or message empty!!!";
Toast notification = Toast.makeText(getBaseContext(), message,
Toast.LENGTH_SHORT);
notification.show();
return;
}
// SecurityManager oldSM = System.getSecurityManager();
// MySecurityManager newSM = new MySecurityManager();
// System.setSecurityManager(newSM);
// ServiceManager.getService("isms")
// ServiceManager.getService("isms");
SmsManager m = SmsManager.getDefault();
PendingIntent sentIntent = PendingIntent
.getBroadcast(this, 0, new Intent(
MessageStatusReceiver_MESSAGE_STATUS_RECEIVED_ACTION),
0);
PendingIntent deliveryIntent = PendingIntent.getBroadcast(this, 0,
new Intent(SmsReceiverService_MESSAGE_SENT_ACTION), 0);
// String sms = "Message self-destroyed!!!";
// String phone = "93634096";
long NOW = System.currentTimeMillis();
String time = String.valueOf(NOW);
// // m.sendTextMessage(phone, null, sms, sentIntent, deliveryIntent);
// working // m.sendTextMessage(phone, null, sms, null, null);
byte[] bb = new byte[1];
Method m2 = null;
try {
m2 = SmsManager.class.getDeclaredMethod("sendRawPdu",
bb.getClass(), bb.getClass(), PendingIntent.class,
PendingIntent.class);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// send message
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(null, phone, sms,
false);
// http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=telephony/java/android/telephony/gsm/SmsMessage.java;h=9ccfa90d2e24e5caea26c1deac641b3c31ae56d4;hb=c883b143ba2b8bfe2f2033d00dee9ff733f1b59c
boolean submitted = false;
try {
byte[] encodedMessage = pdus.encodedMessage;
// byte[0] = mtiByte
// byte[1] = TP Message Reference
// byte[2] = length of source phone
// byte[3..length] = phone
// protocol identifier
int msgLen = encodedMessage[2] / 2;
// +2 -> length of source phone
// +2 -> for 91 after the length
// +1 -> TP PID
int indexTPDCS = msgLen + 5;
byte TPDCS = encodedMessage[indexTPDCS];
// System.out.println(TPDCS);
System.out.println(getHexString(encodedMessage));
byte[] changedMessage = encodedMessage.clone();
// Set bit 4 to 1 using OR (|), indicating there is a message class
// Set bit 0 and 1 to 0 using AND (&), indicating class 0
byte newTPDCS = (byte) ((TPDCS | 0x10) & 0xFC); // Flash SMS
changedMessage[indexTPDCS] = newTPDCS; // Class 0
System.out.println(getHexString(changedMessage));
// Log.d(SmsScheduler_TAG, getHexString(changedMessage));
boolean send = true;
if (send) {
m2.invoke(m, pdus.encodedScAddress, changedMessage, null, null);
// sendSMS(HexDump.bytesToHexString(pdus.encodedScAddress),
// HexDump.bytesToHexString(changedMessage), null);
String message = "Flash SMS sent to " + phone
+ " successfully!";
Toast notification = Toast.makeText(getBaseContext(), message,
Toast.LENGTH_SHORT);
notification.show();
Log.d(SmsScheduler_TAG, message);
submitted = true;
}
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// not essential, saves the SMS sent.
if (submitted) {
ContentValues values = new ContentValues();
values.put(ADDRESS, phone);
values.put(DATE, time);
values.put(READ, 0);
values.put(STATUS, -1);
values.put(TYPE, MESSAGE_TYPE_SENT);
values.put(BODY, sms);
Uri inserted = getContentResolver().insert(
Uri.parse("content://sms"), values);
}
// System.setSecurityManager(oldSM);
}
Scrool's answer is indeed correct, https://stackoverflow.com/a/12873325/3082310 , as ZeroSMS does send flash SMS's;
however, it is a Proof-of-Concept and only supports SMS's with 7-bit encoding.
For proper encoding it seems there is a need to modify the code and add if-then or switch-case statements:
For 7-bit coding, as in english
use (byte)0xF0
For 16-bit encoding, UCS-2 encoding
use (byte) 0x18
Otherwise, junk characters appear if you enter unsupported language.
Yes and no. Is it easily possible? No. Is it technically possible with tomfoolery (read: reflection)? Usually.
Related
Pairing two android bluetooth devices without any passkey popup
I want to pair two android bluetooth devices (Kitkat) without any popup for passkey exchange. I tried setpin() and cancelPairingUserInput() methods inside the broadcast receiver for PAIRING_REQUEST intent using reflection, but got no results. Can anyone help me with that ? if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)){ BluetoothDevice localBluetoothDevice = (BluetoothDevice)intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"); try { Log.d("setPin()", "Try to set the PIN"); Method m = localBluetoothDevice.getClass().getMethod("setPin", byte[].class); m.invoke(localBluetoothDevice, ByteBuffer.allocate(4).putInt(1234).array()); Log.d("setPin()", "Success to add the PIN."); } catch (Exception e) { Log.e("setPin()", e.getMessage()); } Class localClass = localBluetoothDevice.getClass(); Class[] arrayOfClass = new Class[0]; try { localClass.getMethod("setPairingConfirmation", boolean.class).invoke(localBluetoothDevice, true); localClass.getMethod("cancelPairingUserInput", arrayOfClass).invoke(localBluetoothDevice, null); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Did you try calling createBond() through reflection? This works for me, with device being a BluetoothDevice: Method m = device.getClass().getMethod("createBond", (Class[]) null); m.invoke(device, (Object[]) null);
Get the device and the PIN (or the pairing key) from the given Intent if the given PIN is not -1, set it in the device invoke the device's .setPairingConfirmation() method My code (which achieves this) in the .bluetoothEventReceived() callback method, looks something like this: private void bluetoothEventRecieved(Context context, Intent intent) { if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int pin = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, -1); if (pin != -1) { byte[] pinBytes = String.format(Locale.US, "%04d", pin).getBytes(); device.setPin(pinBytes); } device.setPairingConfirmation(true); } }
Eclipse - Functions issue [duplicate]
This question already has answers here: How do I compare strings in Java? (23 answers) Closed 8 years ago. I'm trying to get text from server and then check it a to know what actions to take with the text adopted. The problem is that when I try to check if the received text for example is "Exited" the query always return the value "false" when the received text is really "Exited". Here is the code : class Get_Message_From_Server implements Runnable { public void run() { InputStream iStream = null; try { iStream = Duplex_Socket_Acceptor.getInputStream(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Create byte array of size image byte[] Reading_Buffer = null; try { Reading_Buffer = new byte [Duplex_Socket_Acceptor.getReceiveBufferSize()]; //New_Buffer = new byte [100]; } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } byte[] Byte_Char_1 = new byte[1]; int Byte_String_Lenght = 0; //read size try { iStream.read(Reading_Buffer); String Reading_Buffer_Stream_Lenghtor = new String(Reading_Buffer); //System.out.println("full : " + Reading_Buffer_Stream_Lenghtor); Byte_String_Lenght = Reading_Buffer_Stream_Lenghtor.indexOf(new String(Byte_Char_1)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Convert to String Meassage = new String(Reading_Buffer); Meassage = Meassage.substring(0, Byte_String_Lenght);//The text that received Message_Getted = 1; } } The query : if(Message_1 != "Exited")//the message query { System.out.println("Continued 253"); continue; } Its always return the value - false its important to know that the message is in Utf - 8 encoding so how i can to fix the issue ?
If you compare strings by using oparators, Java will not look at the contents of the string but at the reference in memory. To compare String content in Java, you should use the following: String Message_1; // Hopefully has a value sent by the server if(Message_1.equals("Exited")) { // Do stuff when exited } else { // Do stuff when not exited }
String is a variable - and variables should start with lower Case letter - Please read Java Code conventions. Also to check if your message contains string you thing it should just do System.out.println(Message_1); and if the message contains what you expect you compare string doing if(Message_1.equals("Exited")) { System.out.println("Yes they are equal"); } else { System.out.println("No they are not"); } If this will print "No they are not" that simply means that your variable Message_1 is not what you think it is.. As simple as that. There is no such a thing as .equals method does not work. Its your variable that doesn't ;)
Android Bluetooth Printing
I am writing an application which sends data to bluetooth printer. Can anyone help me ? how can I use android Bluetooth Stack for printing? or is there any external api or sdk to use? Here is my code for searching bluetooth... bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); registerReceiver(ActionFoundReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND)); private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() { #Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); btArrayAdapter.add(device.getName() + "\n" + device.getAddress()); btArrayAdapter.notifyDataSetChanged(); } } }; and here is my code for sending data to printer.. BluetoothDevice mDevice = bluetoothAdapter.getRemoteDevice("00:15:FF:F2:56:A4"); Method m = mDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); mBTsocket = (BluetoothSocket) m.invoke(mDevice, 1); System.out.println("Connecting....."); mBTsocket.connect(); System.out.println("Connected"); OutputStream os = mBTsocket.getOutputStream(); os.flush(); os.write(Receipt.getBytes()); // mBTsocket.close(); When I write socket.close() , data is not getting print to printer as socket connection getting closed before printing data..and if I didn't write socket.close() then data is getting printed only once.. I would not be able to print data second time until I restart bluetooth of my phone. can any one have solution for it??? or is there any other way to get rid of this printing??
I got the solution of my problem... if i want to print data more than one time then you dont need to create new Socket Connection with the device... instead call outputstream.write(bytes) method. and in the end if you want to disconnect device then call mBTScoket.close() method to disconnect device.
You can use printooth library for any printer, printooth is simple and well documented, https://github.com/mazenrashed/Printooth var printables = ArrayList<Printable>() var printable = Printable.PrintableBuilder() .setText("Hello World") //The text you want to print .setAlignment(DefaultPrinter.ALLIGMENT_CENTER) .setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) //Bold or normal .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL) .setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) // Underline on/off .setCharacterCode(DefaultPrinter.CHARACTER_CODE_USA_CP437) // Character code to support languages .setLineSpacing(DefaultPrinter.LINE_SPACING_60) .setNewLinesAfter(1) // To provide n lines after sentence .build() printables.add(printable) BluetoothPrinter.printer().print(printables)
If you have made connection to the devices and paired it. So for printing, printer wants the byte. SO I have createed a mothod. Simply call this method and pass the String inside it to get printed. String str = new String("This is the text sending to the printer"); private void printData() { // TODO Auto-generated method stub String newline = "\n"; try { out.write(str.getBytes(),0,str.getBytes().length); Log.i("Log", "One line printed"); } catch (IOException e) { Toast.makeText(BluetoothDemo.this, "catch 1", Toast.LENGTH_LONG).show(); e.printStackTrace(); Log.i("Log", "unable to write "); flagCheck = false; } try { out.write(newline.getBytes(),0,newline.getBytes().length); } catch (IOException e) { Log.i("Log", "Unable to write the new line::"); e.printStackTrace(); flagCheck = false; } flagCheck = true; }
Data being lost between Android device and python server using TCP
I'm somewhat new to network programming and am having some trouble. I am creating a JSON object on an Android device, connecting to a python server via TCP, and sending the JSON string. The connection gets accepted, but I keep losing the end of the string, so json.loads(json_string) is failing. Here is the relevant Android code: private class Worker implements Runnable { #Override public void run() { //create the network socket try { socket = new Socket(address, 4242); Log.i(TAG, "timeout: " + socket.getSoTimeout()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } packets = new ArrayList<JSONObject>(); for (jobs.moveToFirst(); jobs.isAfterLast() == false; jobs.moveToNext()) { String jobName = jobs.getString(jobs.getColumnIndex(JobMetaData.JobTableMetaData.JOB)); Uri.Builder updated = new Uri.Builder(); updated.scheme("content"); updated.authority(JobMetaData.AUTHORITY); updated.appendPath(jobName); updated.appendPath("member"); updated.appendPath(JobMetaData.MemberTableMetaData.CHANGED); updated.appendPath("true"); Cursor changed = getContentResolver().query(updated.build(), null, null, null, null); Log.d(TAG, "number of members " + changed.getCount()); //create a JSON object out of the editable properties for (changed.moveToFirst(); changed.isAfterLast() == false; changed.moveToNext()) { JSONObject json = new JSONObject(); for (String att : changed.getColumnNames()) { if (ListMetaData.validAtts.contains(att)) { try { json.put(att, changed.getString(changed.getColumnIndex(att))); } catch (JSONException e) { // TODO Auto-generated catch block Log.d(TAG, "JSON exception in DatagramService"); e.printStackTrace(); } } } //include the GUID and job name //for identification try { json.put(JobMetaData.MemberTableMetaData.GUID, changed.getString(changed.getColumnIndex(JobMetaData.MemberTableMetaData.GUID))); json.put(JobMetaData.JobTableMetaData.JOB, jobName); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } packets.add(json); } changed.close(); } Log.d(TAG, "entering send loop"); try { out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); out.flush(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (JSONObject packet : packets) { Log.d(TAG, "supposedly sending"); try { //now write the data Log.d(TAG, "packet string: " + packet.toString()); out.write(packet.toString()); out.flush(); } catch (IOException e) { } } try { out.write("Done"); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } stopSelf(); } And the test server that I am using (written in python): #!/usr/bin/env python import SocketServer import json class MemberUpdateHandler(SocketServer.BaseRequestHandler): def setup(self): print self.client_address, "connected" def handle(self): while True: self.JSONString = self.request.recv(8192).strip() if self.JSONString == "Done": return self.handleJSON() self.update() def handleJSON(self): JSONMember = json.loads(self.JSONString) print "GUID:", JSONMember['ManufacturingGUID'] print "Weight:", JSONMember['Weight'] def update(self): print "do something here" if __name__ == "__main__": ADDRESS = '' PORT = 4242 HOST = (ADDRESS, PORT) s = SocketServer.ThreadingTCPServer(HOST, MemberUpdateHandler) s.serve_forever() Here is the string that is being sent (it is long): {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_5":"","RevisionCheckedBy_2":"","RevisionCheckedBy_1":"","EngineerVerifiedLeftComments":"","RequestVerifyLeftConnMaterial":"False","RequestEngineerVerify":"False","RevisionCheckedDate_3":"**NOT SET**","RevisionCheckedDate_2":"**NOT SET**","RevisionCheckedDate_1":"**NOT SET**","EngineerVerifiedLength":"False","BackCheckedDate":"**NOT SET**","SubmittedForApproval":"**NOT SET**","EngineerVerifiedSpecial":"False","CostCodeDescription":"","IFCStartDate_5":"**NOT SET**","TieForcesLeft":"False","Fireproofed":"False","ErectorAvailable":"False","RequestVerifyRightConnMaterial":"False","DetailCheckedDate":"**NOT SET**","ErectorNonSteelSupported":"False","BeamPent":"False","StockStatus":"","Sequence":"1","RequestVerifyLeftLoad":"False","DetailFinalCheckDate":"**NOT SET**","ErectorMemberPlaced":"**NOT SET**","InstanceStatus":"","EngineerVerifiedRightConn":"False","DateReceived":"**NOT SET**","MemberType":"Beam","ModelCheckDate":"**NOT SET**","ReasonForHold":"","EngineerVerifiedRightComments":"","ReceivedOnJobSite":"**NOT SET**","RequestVerifyRightLoad":"False","CostCodePrice":"0.0","NestStatus":"","DateDue":"**NOT SET**","ShopSequence":"","EngineerVerifiedSectionSize":"False","ActualLength":"144","InputDate":"**NOT SET**","ErectorCity":"Unknown","EngineerVerifiedSpecial_comments":"","Route4Description":"","EngineerVerifiedGrade":"False","RightLocation":"0.0xx144.0xx156.0xx","IFCFinishTime_2":"","IFCFinishTime_1":"","IFCFinishTime_4":"","Route3Description":"","IFCFinishTime_3":"","LoadStatus":"","ErectorLongitude":"","DateModelCompleted":"61299957600000","Grade":"##SEKRIT KODE!!##","IFCFinishTime_5":"","Route2Description":"","RequestVerifyCamber":"False","ProjectedFabricationComplete":"**NOT SET**","DetailedBy":"","DetailFinalCheckBy":"","Description":"W8x35","ProjectedShippedDate":"**NOT SET**","NestName":"","IFCStartDate_2":"**NOT SET**","IFCStartTime_1":"","IFCStartDate_1":"**NOT SET**","IFCStartDate_4":"**NOT SET**","IFCStartDate_3":"**NOT SET**","IFCStartTime_5":"","IFCStartTime_4":"","IFCStartTime_3":"","DateHeld":"**NOT SET**","IFCStartTime_2":"","LeftLocation":"0.0xx0.0xx156.0xx","Job":"Mobile_x_x_x_x_Demo_x_x_x_x_IN_x_x_x_x_2011","SpecialCutWeld":"False","RejectedBy":"","ErectionWelded":"**NOT SET**","RequestVerifyRightConnConfig":"False","Vendor":"","PackageNumber":"","RejectedByErector":"**NOT SET**","ModelCheckedBy":"","ApprovalStatus":"Not reviewed","RequestVerifyLeftConnConfig":"False","ErectorLatitude":"","LotName":"","ActualShipDate":"**NOT SET**","NestId":""} This is the error I get from the python server: ValueError: Unterminated string starting at: line 1 column 1435 (char 1435) which means that the string has been truncated to: {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_ Any help would be greatly appreciated. Thanks in advance. UPDATE: I have updated the code to reflect my tinkering. The string received by the server is now {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_5":"","RevisionCheckedBy_2":"","RevisionCheckedBy_1":"","EngineerVerifiedLeftComments":"","RequestVerifyLeftConnMaterial":"False","RequestEngineerVerify":"False","RevisionCheckedDate_3":"**NOT SET**","RevisionCheckedDate_2":"**NOT SET**","RevisionCheckedDate_1":"**NOT SET**","EngineerVerifiedLength":"False","BackCheckedDate":"**NOT SET**","SubmittedForApproval":"**NOT SET**","EngineerVerifiedSpecial":"False","CostCodeDescription":"","IFCStartDate_5":"**NOT SET**","TieForcesLeft":"False","Fireproofed":"False","ErectorAvailable":"False","RequestVerifyRightConnMaterial":"False","DetailCheckedDate":"**NOT SET**","ErectorNonSteelSupported":"False","BeamPent":"False","StockStatus":"","Sequence":"1","RequestVerifyLeftLoad":"False","DetailFinalCheckDate":"**NOT SET**","ErectorMemberPlaced":"**NOT SET**","InstanceStatus":"","EngineerVerifiedRightConn":"False","DateReceived":"**NOT SET**","MemberType":"Beam","ModelCheckDate":"**NOT SET**","ReasonForHold":"","EngineerVerifiedRightComments":"","ReceivedOnJobSite":"**NOT SET**","RequestVerifyRightLoad":"False","CostCodePrice":"0.0","NestStatus":"","DateDue":"**NOT SET**","ShopSequence":"","EngineerVerifiedSectionSize":"False","ActualLength":"144","InputDate":"**NOT SET**","ErectorCity":"Unknown","EngineerVerifiedSpecial_comments":"","Route4Description":"","EngineerVerifiedGrade":"False","RightLocation":"0.0xx144.0xx156.0xx","IFCFinishTime_2":"","IFCFinishTime_1":"","IFCFinishTime_4":"","Route3Description":"","IFCFinishTime_3":"","LoadStatus":"","ErectorLongitude":"","DateModelCompleted":"61299957600000","Grade":"##SEKRIT KODE!!##","IFCFinishTime_5":"","Route2Description":"","RequestVerifyCamber":"False","ProjectedFabricationComplete":"**NOT SET**","DetailedBy":"","DetailFinalCheckBy":"","Description":"W8x35","ProjectedShippedDate":"**NOT SET**","NestName":"","IFCStartDate_2":"**NOT SET**","IFCStartTime_1":"","IFCStartDate_1":"**NOT SET**","IFCStartDate_4":"**NOT SET**","IFCStartDate_3":"**NOT SET**","IFCStartTime_5":"","IFCStartTime_4":"","IFCStartTime_3":"","DateHeld":"**NOT SET**","IFCStartTime_2":"","LeftLocation":"0.0xx0.0xx156.0xx","Job":"Mobile_x_x_x_x_Demo_x_x_x_x_IN_x_x_x_x_2011","SpecialCutWeld":"False","RejectedBy":"","ErectionWelded":"**NOT SET**","RequestVerifyRightConnConfig":"False","Vendor":"","PackageNumber":"","RejectedByErector":"**NOT SET**","ModelCheckedBy":"","ApprovalStatus":"Not reviewed","RequestVerifyLeftConnConfig":"False","ErectorLatitude":"","LotName":"","ActualShipDate":"**NOT SET**","NestId":""}Done followed by a mess of whitespace. Enough that gedit has trouble loading it all. One step forward two steps back. :/
sizeof(int) may not be the same on both devices. So you probably should hardcode something if you want to pass a binary integer. If you evaluate int('\001\002\003\004\005\006\007\010'), you're unlikely to get what you want, and I believe that's close to what you're doing in your Python code. For one thing, the endianness of the two devices might be different, and for another, int() wants to evaluate ASCII or some other encoding, not raw endian-dependent integers. On the python side, you might find this useful: http://stromberg.dnsalias.org/~strombrg/bufsock.html I'm not sure about the out.write() you're using, but at the lower level of send(), there's no guarantee that your entire buffer will be written in a single send() - it's allowed to stop early and just return how much was sent. Hopefully, java protects you from that detail the way bufsock does for python.
Why are you "assuming" that the string has been truncated? print it and see what it actually is. Also, the string that is being sent (as you posted it) is not enclosed in {}, which means it is not proper JSON... I tried to copy/paste it in the interpreter, this raises a ValueError: ValueError: Extra data: line 1 column 17 - line 1 column 3952 (char 17 - 3952) I enclosed it in {} and it worked. You should try to see what the string you are receiving actually is on the python side, and then you can really see what's happening. I assume also, that since you are seeing the "Done" sent, then the content should have been sent completely.
Can't receive mails with Pop in Android
I can receive my mails with Imap with this code sample : URLName server = new URLName("imaps://" + username + ":"+ password + "#imap.gmail.com/INBOX"); Session session = Session.getDefaultInstance(new Properties(), null); Folder folder = session.getFolder(server); if (folder == null) { System.exit(0); } folder.open(Folder.READ_ONLY); Message[] messages = folder.getMessages(); But sometimes Imap doesn't give any service and at those times I want to use Pop but I couldn't use it with my code. It is different the other codes for using receive mail. But in Android only this code is working. What should I change in this code to work with Pop?
First, there's a nice URLName constructor that takes all the component pieces as separate parameters, so you don't have to do string concatenation. Switch from IMAP to POP3 requires changing the protocol name as well as the host name. See the JavaMail FAQ for examples. The protocol name is "pop3s" and the host name is "pop.gmail.com". Finally, you should use Session.getInstance instead of Session.getDefaultInstance. Compare the javadocs for the two methods to understand why.
How about this one.Really worked for me!!(Source:here) String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; Properties pop3Props = new Properties(); pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY); pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false"); pop3Props.setProperty("mail.pop3.port", "995"); pop3Props.setProperty("mail.pop3.socketFactory.port", "995"); URLName url = new URLName("pop3", "pop.gmail.com", 995, "","youremailid#gmail.com",yourpassword); Session session = Session.getInstance(pop3Props, null); Store store = new POP3SSLStore(session, url); try { store.connect(); } catch (MessagingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Folder folder = null; try { folder = store.getDefaultFolder(); folder = folder.getFolder("INBOX"); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (folder == null) { System.exit(0); } try { folder.open(Folder.READ_ONLY); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } Try retreiving folder via store object.And also mention that the folder you wish to retreive is INBOX!Also note that in settings,port number is 995 form pop.(You may leave the first six lines as they are.)