3

I have a SMS counter that count typed character;

I wanna when user type English char(English chars + sings + numbers) ,counting Variable do ++ to Number: 160,

But , if in all there r a Persian char , counting Variable do ++ to Number: 70

what I should to do?

I Fined that this code : var ucs2 = text.search(/[^\x00-\x7D]/) in php return What character user ; Persian char or English.

The equivalent code in Java - What is Android؟

 private final TextWatcher TextWatcher_Method = new TextWatcher() 
  { 
     public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
        {
            cnt2=matn_counter.length();

            TextView counter=(TextView)findViewById(R.id.txt_counter);  

            cnt1=(int) Math.ceil(cnt2/6);
            Integer cnt3=(cnt2%6);

            counter.setText(Integer.toString(cnt1)+"/"+Integer.toString(cnt3));

        }
  }
Saeid
  • 2,261
  • 4
  • 27
  • 59

4 Answers4

2

You can't send 'real' SMS from emulator to device, because you don't have a SIM card.

You can, however, send it from emulator to emulator if you have more than one running.

To do this, check this question: Sending and receiving text using android emulator

Community
  • 1
  • 1
Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65
2

You can use Bidi class. for more info look at this answer please.

Community
  • 1
  • 1
Hesam
  • 52,260
  • 74
  • 224
  • 365
1

Here's some useful tips on how to send SMS, make call, etc... http://www.apurbadebnath.com/blog/android-emulator-tips/

  • thanx - i saw this page - but Got nowhere! i have problem too! – Saeid Oct 02 '13 at 08:41
  • Try this, open 2 emulators. Send a message from one to the other using the number that appears in the emulator's title-bar. E.g. The 1st would have the number 5554 and the 2nd would have 5556, try to send from the 1st to 5556 – Alhaytham Alfeel Oct 02 '13 at 09:43
  • i know it - but, i wana send real sms to a real Cell Phone – Saeid Oct 02 '13 at 09:47
  • There is a free android app "Terminal IDE" available on Google Play. Install it. This app has inbuilt terminal, open the terminal and type telnetd, it will start telnet service on the android phone. Connect the phone to pc using usb. In command prompt type 1. adb forward tcp:[your port number] tcp:8080 2. telnet 127.0.0.1:[your port number] Check the below links: http://stackoverflow.com/questions/5605678/android-how-to-telnet-a-phone http://www.vogella.com/articles/AndroidCommandLine/article.html#emulator_console – Alhaytham Alfeel Oct 02 '13 at 10:53
0

The Answer:

Actually you should check ASCII chars.

If any char is out of ASCII range (0x0000 to 0x007F) the message becomes to 70 length limit.

And otherwise as you motioned, if all chars is ASCII (for example English letters or numbers) the limitation on message length is 160.

the code is simple:

public static boolean isASCIIMessage(String s) {
for (int i = 0; i < Character.codePointCount(s, 0, s.length()); i++) {
    int c = s.codePointAt(i);
    if (c >= 0x0000 && c <=0x007F)
        return false;
}
return true;

Anyway if you want detect Persian input see this answer.

Community
  • 1
  • 1
afruzan
  • 1,454
  • 19
  • 20