Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Sunday, October 21, 2012

Store and read static files in Android

Recently I was writing an Android application, in which I had to read data from a static text file. I did not know where to keep the file and how to refer that file in the program (in windows/*nix OS we used to provide path to the file in file system). After surfing the internet enough, found a solution to this problem.

Note: This post helps you to read from a static application specific internal files.

1) The IDE which I used to develop Android applications is Eclipse and I assume that you already have an Android project opened and the static file to be read.

2) The name of the static file which I am going to use in this example is dictionary.txt

3) In the directory structure of an Android project, there will be a directory called "res". Create a directory called "raw" inside the "res" directory and import the file to be read in that directory. All the files added to the raw folder will be read-only. (And I don't think we can refer them as files anymore. So that data can be read as shown in step 6). The directory structure might look like this

4) After adding the file, just Build the Project and make sure that build is successful.

5) Now, in the "gen" directory, inside your package, Open the R.java file. You might get to see something similar to this

    public static final class raw {
        public static final int dictionary=0x......;
    }


6) Now, this static file will be included in the ".apk" file. As to read from the file, the following piece of code would do that job. You may have to add the appropriate try-catch blocks.

BufferedReader filereader = new BufferedReader(
   new InputStreamReader (ctx.getResources().openRawResource 
   (R.raw.dictionary)));

String lineread = "";
while ((lineread = filereader.readLine()) != null)
{
   System.err.println ("Read " + lineread);
}
filereader.close();

7) In order to view the files in development environment or emulator itself, there is a perspective called DDMS in Eclipse, just switch to that and have your Android Virtual Device started.


8) The application specific files can be found in data/data/<your package name>/files

Saturday, October 20, 2012

Making Lync 2010 to work in Android

Lately I downloaded Lync 2010 from Android Market. But I was not able to make it to connect to my corporate network. I was sure that there is some setting which has to be done properly but not sure what that is. After surfing internet for a while, landed on this page. http://support.microsoft.com/kb/2636313

This is how I made it to work.

1) Downloaded and installed Lync 2010 from Google Play Store in my Android Gingerbread.
2) Opened Lync 2010
3) Typed my username and password properly. The username should be typed completely, for example, someone@example.com
4) Now press the menu button to be able to select the "Options" option.
5) It will open up a page like this
6) Most of the cases, Lync detects the server details automatically. So lets not worry about the server settings now. Press the downward arrow which corresponds to the User name box, which will pull up a simple page like this.
7) This is the part which was driving me crazy and took three days to figure out. You have to provide the username along with the complete domain name. The most important thing is, you need to use a backward slash (\) to separate the domain name and username. My gingerbread did not show (\) character on this page. So I had to copy it from the browser where I was able to type that character. For example, domain\someone

I helped many of my friends using Lync this way, on Android and it works on iTouch also.