Recent Notes

Displaying keyword search results 11 - 20
Created by magnum on February 22, 2012 16:04:38    Last update: February 22, 2012 16:04:38
A simple single threaded echo server: #include <stdio.h> #include <stdlib.h> #incl...
Created by lokf on January 13, 2012 14:10:42    Last update: January 13, 2012 14:10:42
For some reason I don't know writing to files in Android is very complicated and tedious. Here is some code for those who might need it. Apps should write in the SD in the directory /Android/data/package_name/files/ so that it is deleted with the app uninstall. package randomname; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.ByteBuffer; import android.content.Context; import android.os.Environment; import android.util.Log; public class FileIOLibrary { String packageName; boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; FileIOLibrary(String packageNamep) { this.packageName=packageNamep; } public boolean isExternalStorageAvailable() { updateExternalStorageState(); return mExternalStorageAvailable; } public boolean isExternalStorageWritable() { updateExternalStorageState(); return mExternalStorageWriteable; } /** * writes the current state of SD card to the corresponding variables */ void updateExternalStorageState() {...
Created by magnum on October 09, 2011 19:53:26    Last update: October 09, 2011 19:53:50
#include <stdio.h> #include <stdlib.h> #incl... UNIXguide.net explains this option well: This socket option tells the kernel that even if this port is busy (in the TIME_WAIT state), go ahead and reuse it anyway. If it is busy, but with another state, you will still get an address already in use error. It is useful if your server has been shut down, and then restarted right away while sockets are still active on its port. You should be aware that if any unexpected data comes in, it may confuse your server, but while this is possible, it is not likely. It has been pointed out that "A socket is a 5 tuple (proto, local addr, local port, remote addr, remote port). SO_REUSEADDR just says that you...
Created by magnum on October 06, 2011 14:35:20    Last update: October 06, 2011 14:35:20
The longjmp function jumps to the line where setjmp was last called. In return, setjmp returns the value passed in as the second parameter to longjmp . #include <stdio.h> #include <stdlib.h> #incl... Result: $ ./longjmp val is 0 val is 1 --> val is ...
Created by magnum on October 06, 2011 12:32:21    Last update: October 06, 2011 12:32:21
What's the value of INADDR_ANY ? You can look it up in header files, but it's equally easy to get it with a little code: #include <stdio.h> #include <arpa/inet.h> ... Output: $ ./inaddrvalue INADDR_ANY value: 0.0.0.0
Created by magnum on September 27, 2011 21:51:05    Last update: September 28, 2011 18:02:49
Client socket usually does not call bind . But I've seen code that does and it was puzzling to me what bind does to a client socket. Therefore, this little test program. It retrieves a web url and displays info about the socket. You can optionally give a bind host name/ip and port and see what it does. Here are my test results: $ ./client www.google.com Local addr: 172.16.0.... This is the code: #include <stdio.h> #include <stdlib.h> #incl...
Created by magnum on September 25, 2011 21:51:23    Last update: September 26, 2011 20:49:22
A simple socket client in C. #include <stdio.h> #include <stdlib.h> #incl...
Created by freyo on May 13, 2011 15:45:29    Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator. build.xml : <?xml version="1.0" encoding="UTF-8"?> <project... AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <man... res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <Lin... res/values/strings.xml : <?xml version="1.0" encoding="utf-8"?> <res... src/com/android/xmltool/DumpXml.java package com.android.xmltool; import java.ut... Screenshot Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by magnum on September 11, 2011 21:31:45    Last update: September 11, 2011 21:32:00
The warning message was emitted by the gcc compiler with the " -Wdeclaration-after-statement " switch: $ gcc -Wdeclaration-after-statement hello.c for the following code: #include <stdio.h> int main(int argc, char* arg... There were no warnings without the " -Wdeclaration-after-statement " switch. GCC manual says: -Wdeclaration-after-statement (C and Objective-C only) Warn when a declaration is found after a statement in a block. This construct, known from C++, was introduced with ISO C99 and is by default allowed in GCC. It is not supported by ISO C90 and was not supported by GCC versions before GCC 3.0.
Created by freyo on July 27, 2011 12:13:52    Last update: July 27, 2011 12:13:52
Implement the provider. Put the initialization code in onCreate , implement the necessary query and update methods. This is a skeleton: package my.package; import android.content.... Declare the content provider in AndroidManifest.xml , with content authority (any string identifier): <?xml version="1.0" encoding="utf-8"?> <manifes... Use the provider (content consumer code): // import android.content.ContentResolver; Cont...
Previous  1 2 3 4 5 6 7 Next