Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, August 02, 2012

Error when implementing AdMob into existing Android app



After a successful application of AdMob, next step to start your Ads business is integrate the AbMob into your apps. I am not going through the detail as, its really simple for person who can write your own apps.

I just want to share some experience during the implementation,  especially when your existing apps are developed based on Android 2.3 or prior version.

if you following the guideline from Google AdMob, you may get the following error

<activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>


error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').


When your are using AdMob V6+, you apps SDK must be Android 3.2 (target SDK 13) or above. For new I recommend you to use Android SDK 4.0.3 (SDK 15), as Android 3.2 was for Tablet.

1. In AndroidManifest.xml, make the changed as below. remeber to setup your minSdkVersion, or your existing coding may not be run.



    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15"/>

 2. Make the following changes in "project.properties" file
 
 
 
# Project target.
target=android-15


Please note after the implementation. you lay out will have become Android 4.0 stylus. UI appearance may be changed.




Tuesday, July 31, 2012

"unable to resolve target" and "Unable to get system library for the project"

Have you even tried to import an Android Project into Eclipse, but get error like "unable to resolve target" and "Unable to get system library for the project" ? If so, this post may help.




 In sometimes, the error was caused by unavailable of certain Android SDK version. The project may be build based on a version of Android SDK, that your Eclipse had not installed.

To solve the issue, just following the steps below.

1. In Eclipse, right click your project > Properties.
2. Click Android, select a build target and "ok"
3, When you go back to Eclipse, clokc, Project > Clean > Clean all projects

Then back to your .java and all error should be removed.

p.s. The nice example was came from How to convert an Activity class to use with FragmentPagerAdapter

Monday, July 30, 2012

"R cannot be resolved" error

For "R cannot be resolved" error, in most cases, the problem may relied on the Java itself, but /res/values/strings.xml. Make sure the syntax of XML is correct.


Sunday, July 29, 2012

Upgrade and Versioning of your apps



If you have developed feature or bug fix your Android apps, you have to change the version of your app, before you can upload it to Google Play.

versionCode - Integer only. That's the version of your application code. You must change (normally +1) its or Google Play will not allow you upload the APK.

versionName - String. Version name that all users can see. So that they can identify which version they are using. (normally in format like 1.0.2)





See more in Android Developer - Versioning Your Applications

Saturday, July 28, 2012

Hiding Option Menu



In some situation, you developed an app with optional menu but wants temporary disable it for reason. You may use .setVisible(false).

Before move on to an example, I expect you are familiar with Android Option Menu, if not, please read this this first.

I have prepared an option menu defined below

	

    
      
          android:icon="@drawable/ic_import"
          android:title="@string/importSD" />
      
      
            android:icon="@drawable/ic_export"
            android:title="@string/exportSD" />
      
      
            android:icon="@drawable/ic_exportdropbox"
            android:title="@string/exportDropbox" />
      
      
            android:icon="@drawable/ic_unlinkdropbox"
            android:title="@string/unlinkDropbox" /> 
      
      
            android:icon="@drawable/ic_babybirthday"
            android:title="@string/babyBirthday" /> 
      
      
            android:icon="@drawable/ic_info"
            android:title="@string/info" />
      
      
 
 

Then, when the main java, add the following class and set your desired option menu to disable


	

	boolean isLiteVersion = true;
	@Override
	public boolean onPrepareOptionsMenu (Menu menu) {
		if (isLiteVersion)	{
			menu.findItem(R.id.OM_exportSD).setVisible(false);
			menu.findItem(R.id.OM_importSD).setVisible(false);
			menu.findItem(R.id.OM_exportDropbox).setVisible(false);
			menu.findItem(R.id.OM_unlinkDropbox).setVisible(false);
		}
		return true;
	}

Some of the option menu will then be be hidden.




Google Android Developer : Menu

Developing multi-language Android app




Developing your apps with User Interface in Android is easy, but your get to follow the guidelines.
  • Don't hard code text. Use Resource (strings.xml).
  • Avoid integrate text into picture (icon, banner, etc)
  • Use short wording
Let see some an example.
The default language of the apps "Baby milkfeed counter" is English. That mean whatever you device language setting is, the apps will display UI in the English.

Let's focus on the field "Fed Today".

.

 The below is a extract of the /res/layout/main.xml. 



	
		        android:id="@+id/textView1"
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:text="@string/fedToday" />


The above text "@string/fedToday" was a tag stored in /res/values/strings.xml. Text field stored in this file are default language in this app (i.e. English). Let see the extract content of this string.xml.



	



...
...
    Last feed time
    Last volume
    Since last feed
    Fed today
    Fed Yesterday
...
...



Rather than hard code the text "Fed Today" in /res/layout/main.xml , I store it as string in /res/values/strings.xml. In fact, you should store all the text that will display in UI in the strings.xml. To implement multilingual UI, I don't need to change other file, but just add another file, /res/value-<locale>/strings.xml.



For example, to implement the app's UI in Traditional Chinese, I just need to prepare another strings.xml, as in /res/values-zh-rTW/strings.xml.


	



...
...
    上次餵哺時間
    上次餵哺量
    離上次餵哺
    今日已餵
    昨日已餵
...
...



The process is completed. As you can see, the UI development did not involved any Java code, or even any file, just string.xml. To switch between go to the Android setting change the Language. launcher icon and UI textwill changed based on the device setting.



For every setting language, you get to prepare a separate /res/value-<locale>/strings.xml. if the device can find the its own language's string.xml, it uses the default one. Language and the strings.xml path mapping is as below.


Default /res/value/strings.xml
CANADA  /res/value-en-rCA/strings.xml
CANADA-FRENCH  /res/value-fr-rCA/strings.xml
CHINA  /res/value-zh-rCN/strings.xml
CHINESE  /res/value-zh/strings.xml
ENGLISH  /res/value-en/strings.xml
FRANCE  /res/value-fr-rFR/strings.xml
FRENCH  /res/value-fr/strings.xml
GERMAN  /res/value-de/strings.xml
GERMANY  /res/value-de-rDE/strings.xml
ITALIAN  /res/value-it/strings.xml
ITALY  /res/value-it-rIT/strings.xml
JAPAN  /res/value-ja-rJP/strings.xml
JAPANESE  /res/value-ja/strings.xml
KOREA  /res/value-ko-rKR/strings.xml
KOREAN  /res/value-ko/strings.xml
PRC  /res/value-zh-rCN/strings.xml
SIMPLIFIED-CHINESE  /res/value-zh-rCN/strings.xml
TAIWAN  /res/value-zh-rTW/strings.xml
TRADITIONAL-CHINESE  /res/value-zh-rTW/strings.xml
UK  /res/value-en-rGB/strings.xml
US  /res/value-en-rUS/strings.xml



For more locale info  for Android Development  / SDK, check with the following

Supporting Different Languages

Localization

Locale