15

I am new in android. I want to know does android support Unicode. If yes, then how can we use it through java code. I have written a program

TextView tv = new TextView(this);
tv.setText("Hello, চন্দন");
setContentView(tv);

The Bengali unicode characters are coming as boxes.

Thanks in advance.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Chandan
  • 764
  • 2
  • 8
  • 21
  • 2
    Based on Update # 257 at - http://code.google.com/p/android/issues/detail?id=4153#c257 , looks like we could consider that all Unicode Fonts , including Telugu, can now be supported starting 4.2 and more. –  Mar 26 '13 at 22:41
  • See my Reply http://stackoverflow.com/questions/5300391/unicode-support-for-android/39675441#39675441 – Monzur Sep 24 '16 at 10:42

7 Answers7

35

"Supporting Unicode" - which is simply a character encoding standard - and displaying Unicode text in a way that can be read properly are whole different things.

The latter requires both a proper font for the script concerned and a complex text rendering engine which applies rules embedded in the font to display text properly. In Windows this is handled by system library called Uniscribe, on Apple systems by ATSUI, and on Linux systems by Pango. Android is based on Linux but unfortunately Google seem to have removed the parts for handling complex scripts. (A rather strange decision since most Android devices are for communications including text.) Complex scripts work fine on other mobile devices using a Linux based operating system like the Nokia N9 and N900

Android also makes it difficult for users to install additional fonts or keyboard layouts that can be used by different applications without "rooting" their phone or tablet.

A few manufacturers of Android devices have implemented support on their own (e.g. Sony Ericsson's ST and MT series phones seem to support Devanagari and other Indic scipts very well.) On some Android phones Indic scripts will render OK in the browser - because the browser developer has added support of their own - but will not work in other applications.

Please see: http://code.google.com/p/android/issues/detail?id=4153

Until this issue is properly fixed in Android, most devices running this operating system seem to be a poor choice for users who want to use scripts like Devanagari, Tamil, Bengali, Kannada, Punjabi, Telugu, Tibetan, Khmer, Sinhala, Malayalam, Burmese, and so on on their smart phone or tablet.

The part of Android that needs fixing to support complex scripts is libskia.so and libwebcore.so. So, if you are writing applications to support Indian languages, you might want to try replacing these libraries with your own modified versions.

Sahaja
  • 376
  • 3
  • 3
  • 1
    Very good answer; it provides much more detail than my answer. There's one point that wrong, though: "Android also makes it difficult for users to install additional fonts or keyboard layouts that can be used by different applications without 'rooting' their phone or tablet." While Android makes it difficult to install fonts without rooting their phone, new keyboard layouts (and other input methods), can be installed quite easily. See their documentation on implementing [an input method](http://developer.android.com/guide/topics/text/creating-input-method.html) for details. – Brian Campbell Dec 02 '12 at 22:00
  • @sahaja do you know how to replace/override system library? Sounds like we can't do it within an app. But instead we have to root the device and replace the *.so file in `/system/library`. – Hieu Rocker Jun 09 '14 at 11:08
8

Android does support Unicode, but the fonts included don't cover all Unicode characters, and the rendering doesn't support all types of scripts. In particular, the included fonts only cover Western European (Latin), Cyrillic, Greek, and CJK characters. Even if you install new fonts, it appears that Android does not properly support some forms of indic text layout like Devanagari, as mentioned in bug 4153. I'm not familiar enough with the Bengali script to know if it requires any sort of special rendering like Devanagari does, but if it does, then it is likely not supported on Android even if you install a font that supports it.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • why the font installation will not make the Bengali(Devnagari script) language get displayed on Android.WHat if we alter the font file accordingly . – Raulp Aug 06 '12 at 05:15
  • 3
    @softy Because Devanagari requires specialized glyph reordering support; the order that the characters appear in the text is not the same order that they are displayed. Simply changing the font won't help; you need something that can change the order the glyphs are displayed in. This is supported by certain advanced font formats like AAT and Graphite, but Android doesn't support those; so it would need to specifically support Devanagari reordering, or add support for one of those font formats, to properly display Devanagari text. – Brian Campbell Aug 13 '12 at 12:33
  • Cyrillic and Greek are indeed *European* as well. Did you mean **Western**? – Incnis Mrsi Aug 18 '15 at 08:18
  • @IncnisMrsi Yes, I probably meant to write "Western European", or perhaps should have just said "Latin". – Brian Campbell Aug 18 '15 at 12:47
  • Yes, “Latin” IMHO would be least problematical. – Incnis Mrsi Aug 18 '15 at 12:50
3

You may be able to work around this with a specialised font, as seen in this SO answer about Tamil on Android.

Community
  • 1
  • 1
1

I liked the comprehensive answer from Sahaja.

There are some efforts going on to port Harfbuzz-ng rendering engine to android. Here is a link to the source code of porting Harfbuzz-ng for kannada , one of the Indian languages, text rendering.

Supreethks
  • 597
  • 6
  • 16
1

Create a Layout name as list.xml in Layout

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="20sp" >
</TextView>

Add a TextView and a ListView in your activity_main.xml

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/textView" />
<ListView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/listView" />

MainActivity.java

public class MainActivity extends AppCompatActivity {        
    ListView listView;
    TextView textView;

    static final String[] BANGLA = new String[] {
            "Barguna District (বরগুনা)",
            "Barisal District (বরিশাল)",
            "Bhola District (ভোলা)",
            "Jhalokati District (ঝালকাঠি)",
            "Patuakhali District (পটুয়াখালী)",
            "Pirojpur District (পিরোজপুর)",
            "Bandarban District (বান্দরবান)",
            "Brahmanbaria District (ব্রাহ্মণবাড়ীয়া)",
            "Chandpur District (চাঁদপুর)",
            "Chittagong District (চট্টগ্রাম)",
            "Comilla District (কুমিল্লা)",
            "Cox's Bazar District (কক্সবাজার)",
            "Feni District (ফেনী)",
            "Khagrachhari District (খাগড়াছড়ি)",
            "Lakshmipur District (লক্ষ্মীপুর)",
            "Noakhali District (নোয়াখালী)",
            "Rangamati District (রাঙ্গামাটি)",
            "Dhaka District (ঢাকা)",
            "Faridpur District (ফরিদপুর)",
            "Gazipur District (গাজীপুর)",
            "Gopalganj District (গোপালগঞ্জ)",
            "Kishoreganj District (কিশোরগঞ্জ)",
            "Madaripur District (মাদারীপুর)",
            "Manikganj District (মানিকগঞ্জ)",
            "Munshiganj District (মুন্সীগঞ্জ)",
            "Narayanganj District (নারায়ণগঞ্জ)",
            "Narsingdi District (নরসিংদী)",
            "Rajbari District (রাজবাড়ী)",
            "Shariatpur District (শরীয়তপুর)",
            "Tangail District (টাঙ্গাইল)",
            "Bagerhat District (বাগেরহাট)",
            "Chuadanga District (চুয়াডাঙ্গা)",
            "Jessore District (যশোর)",
            "Jhenaidah District (ঝিনাইদহ)",
            "Khulna District (খুলনা)",
            "Kushtia District (কুষ্টিয়া)",
            "Magura District (মাগুরা)",
            "Meherpur District (মেহেরপুর)",
            "Narail District (নড়াইল)",
            "Satkhira District (সাতক্ষিরা)",
            "Jamalpur District (জামালপুর)",
            "Mymensingh District (ময়মনসিংহ)",
            "Netrakona District (নেত্রকোনা)",
            "Sherpur District (শেরপুর)",
            "Bogra District (বগুড়া)",
            "Joypurhat District (জয়পুরহাট)",
            "Naogaon District (নওগাঁ)",
            "Natore District (নাটোর)",
            "Chapainawabganj District (নওয়াবগঞ্জ)",
            "Pabna District (পাবনা)",
            "Rajshahi District (রাজশাহী)",
            "Sirajgonj District (সিরাজগঞ্জ)",
            "Dinajpur District (দিনাজপুর)",
            "Gaibandha District (গাইবান্ধা)",
            "Kurigram District (কুড়িগ্রাম)",
            "Lalmonirhat District (লালমনিরহাট)",
            "Nilphamari District (নীলফামারী)",
            "Panchagarh District (পঞ্চগড়)",
            "Rangpur District (রংপুর)",
            "Thakurgaon District (ঠাকুরগাঁও)",
            "Habiganj District (হবিগঞ্জ)",
            "Moulvibazar District (মৌলভীবাজার)",
            "Sunamganj District (সুনামগঞ্জ)",
            "Sylhet District (সিলেট)"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        textView= (TextView)findViewById(R.id.textView);
        textView.setText(Html.fromHtml("বাংলাদেশের জেলা সমূহ"));
        edittext = (EditText)findViewById(R.id.editText);
        imageView= (ImageView)findViewById(R.id.imageView);

        listView=(ListView)findViewById(R.id.listView);

        listView.setAdapter(new ArrayAdapter<String>(this,R.layout.list, BANGLA));

   }
}

Hope this will Help you...

Monzur
  • 1,341
  • 14
  • 11
1

Bengali script needs ligatures like Devanagari, so, it's faint chance that android would render Bengali properly.

uddip
  • 11
  • 1
0

Android supports Unicode out-of-the box. You're particular language might be not supported though. You can find list of supported locales for each SDK version by looking at Platform Notes.

Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93