Hi All,
I've moved all content to my site , you can follow to http://codingstories.com/ to read old and new posts.
Java Group
Friday, July 15, 2011
Wednesday, July 13, 2011
Android: Localization
Introduction
The next step in development Android application will be localization. I've read documentation from official site and from http://www.icanlocalize.com/ and decided to describe it.
Sequence of resources lookup.
How does android lookup the resources from applications?
The example of lookup steps below:
Dismantle folders structure
The next question that worried me : What does it mean -rUS why is not just en?
The answer is, There are countries with two or more official languages for example Switzerland but there no Swiss language just French or/and German. The fisrt -<symbol>- (in our example -en-) means language, -r means region and after -r name of region. For instance for French language in Switzerland will be
res/values-fr-rCH
This rules works for other resources like pictures and so on.
Conclusion
If you want to localize your application just:
Cheers!
The next step in development Android application will be localization. I've read documentation from official site and from http://www.icanlocalize.com/ and decided to describe it.
Sequence of resources lookup.
How does android lookup the resources from applications?
The example of lookup steps below:
- ‘res/values-en-rUS/strings.xml’
- ‘res/values-en/strings.xml’
- ‘res/values/strings.xml’
Dismantle folders structure
The next question that worried me : What does it mean -rUS why is not just en?
The answer is, There are countries with two or more official languages for example Switzerland but there no Swiss language just French or/and German. The fisrt -<symbol>- (in our example -en-) means language, -r means region and after -r name of region. For instance for French language in Switzerland will be
res/values-fr-rCH
This rules works for other resources like pictures and so on.
Conclusion
If you want to localize your application just:
- create folders for all localized resources using above convention
- put localized files into folders
- start your application
Cheers!
Wednesday, July 6, 2011
Android: Amazing story about sending SMS messages from the code.
Hi,
I have found amazing case of sending sms messages from the code.
Task
I need to send SMS message from my test method and test behavior of parsing it. Just for this post we are interesting in first part: Sending SMS message from code.
I’ve written next simple code:
and tried to test it. Just put this code in simple test method and run Android Unit Test. The result is … nothing!!! Why?!! I did not understand …
Solution
After hours of investigation and reading documentation and blogs I decided to try the same manipulation, BUT, just on two emulators. I have started two emulators on 5554 and 5556 and tried start test project on 5554 but send message to 5556. Simple changes in code below:
And … and … I was surprised, I can see message “Test” on 5556 emulator and it is perfectly!
Cheers!
I have found amazing case of sending sms messages from the code.
Task
I need to send SMS message from my test method and test behavior of parsing it. Just for this post we are interesting in first part: Sending SMS message from code.
I’ve written next simple code:
final SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("5554", null, "Test", null, null);
and tried to test it. Just put this code in simple test method and run Android Unit Test. The result is … nothing!!! Why?!! I did not understand …
Solution
After hours of investigation and reading documentation and blogs I decided to try the same manipulation, BUT, just on two emulators. I have started two emulators on 5554 and 5556 and tried start test project on 5554 but send message to 5556. Simple changes in code below:
final SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("5556", null, "Test", null, null);
And … and … I was surprised, I can see message “Test” on 5556 emulator and it is perfectly!
Cheers!
Tuesday, July 5, 2011
Android: Problems of run Unit Tests
Hi,
I have created separate project for testing my Android Application and tried to start it.
After starting I have received next error:
After few hours of investigation I have found solution for this situation.
Problem:
So, Problem is package in the manifest files. The package in “real” project manifest file and test manifest file are equal. For instance look at the package com.blogspot.jugvn in both manifests
Test manifest:
Project Manifest:
Solution:
Change package in test project to something else, I have used next convention: put test instead of first part of package like this :
test.blogspot.jugvn
And result manifest file should be like this
That is all manipulation for fixing this problem.
Cheers!
I have created separate project for testing my Android Application and tried to start it.
After starting I have received next error:
Test run failed: Unable to find instrumentation info for:
ComponentInfo {<my package>/android.test.InstrumentationTestRunner}
Problem:
So, Problem is package in the manifest files. The package in “real” project manifest file and test manifest file are equal. For instance look at the package com.blogspot.jugvn in both manifests
Test manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blogspot.jugvn"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7" />
<instrumentation
android:targetPackage="com.blogspot.jugvn"
android:name="android.test.InstrumentationTestRunner"
/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library android:name="android.test.runner"
/>
</application>
<!--
Add permissions for send sms messages-->
<uses-permission android:name="android.permission.SEND_SMS"
/>
<uses-permission
android:name="android.permission.WRITE_SMS" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blogspot.jugvn"
android:versionCode="1" android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/visa"
android:debuggable="true">
<activity android:name=".AccountList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="7" android:targetSdkVersion="7"
/>
<!-- Allows an application to
read SMS messages. -->
<uses-permission
android:name="android.permission.READ_SMS" />
</manifest>
Change package in test project to something else, I have used next convention: put test instead of first part of package like this :
test.blogspot.jugvn
And result manifest file should be like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.blogspot.jugvn
"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7" />
<instrumentation
android:targetPackage="test.blogspot.jugvn "
android:name="android.test.InstrumentationTestRunner"
/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library
android:name="android.test.runner" />
</application>
<!-- Add permissions for send sms
messages-->
<uses-permission
android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS"
/>
</manifest>
Cheers!
Android send SMS messages from emulator using Telnet
Hi,
I have started to develop first Android project and will write some notes during development process.
The first note is sending sms messages from terminal.
So, There are a few steps to send messages from emulator using terminal:
I have started to develop first Android project and will write some notes during development process.
The first note is sending sms messages from terminal.
So, There are a few steps to send messages from emulator using terminal:
- Start emulator (The emulator has to be started becaue you need to know port to connect). For starting emulator go to the Andriod SDK and AVD Manager->Virtual Devices->Start
- Start telnet. Type in console window
1: telnet
- Open telnet connection to the emulator port. Type in telnet window
, where localhost name of computer where emulator is running and 5554 it is port of emulator running.
1: o localhost 5554
- Try to send message. Type in telnet window
, where 5556 is phone number, Test Message is text of message.
1: sms send 5556 Test Message
Sunday, May 29, 2011
Preparing to start …
Hi,
All the potential readers of this blog should understand, that I am not a writer. I just trying to write some interesting things about java.
So, go ahead …
All the potential readers of this blog should understand, that I am not a writer. I just trying to write some interesting things about java.
So, go ahead …
Subscribe to:
Posts (Atom)