Data corruption in Binary SMS

by mahantesh Hunagund » Tue, 03 Mar 2009 02:51:50 GMT

Sponsored Links

I am trying to send binary SMS. I am using android SDK 1.0_r2.  My
application is able to receive the SMS, but data I am receiving is
completely change from whatever I am sending.
Please help me in this regard.

My Code looks like
*byte[] data="Google".getBytes();*

*public* *class* smsReceiver *extends* BroadcastReceiver {

*private* *static* *final* String *SMS_RECEIVED* =

*public* *void* onReceive(Context context, Intent intent) {

*if* (intent.getAction().equals(*SMS_RECEIVED*)) {

Bundle bundle = intent.getExtras();

Object messages[] = (Object[]) bundle.get("pdus");

SmsMessage smsMessage[] = *new* SmsMessage[messages.length];

*for* (*int* n = 0; n < messages.length; n++) {

smsMessage[n] = SmsMessage.*createFromPdu*((*byte*[]) messages[n]);


*String str = new** String(smsMessage[0].getUserData());*

Toast toast = Toast.*makeText*(context, "Title: "+ str,Toast.*LENGTH_LONG*);

When I checked with the help of debugger, I am receiving "
4F b, b,  " instead of "Google".



Other Threads

1. Null Pointer Exception while creating table

    I have implement this example. but i got an error.

    I have write the code just for create database, create table,
insert values in it.

    When I run application it displays nothing.

    But when i tried to open my database from command prompt Like:

    ls data/data/MyPackageNm

    Then it gives only a Lib folder rather than database and Lib both.

    So, i tried to found error via Log cat and put my code in try and

    I got an error while creating table.

    its gave Null Pointer exception.

    Please any one help me.

    My Log cat is like that and i have use this sample example as my


Log Cat:-

uid=10032 gids={}
09-29 15:36:09.727: DEBUG/dalvikvm(813): LinearAlloc 0x0 used 538516
of 4194304 (12%)
09-29 15:36:09.837: INFO/jdwp(822): received file descriptor 10 from
09-29 15:36:10.128: INFO/Niketa(822): database created
09-29 15:36:10.137: INFO/Niketa(822): database opened
09-29 15:36:10.137: INFO/Niketa(822): ------null
09-29 15:36:10.147: INFO/Niketa(822): +++++
09-29 15:36:10.337: INFO/ActivityManager(52): Displayed activity
com.db/.DataBaseWork: 754 ms
09-29 15:36:15.507: DEBUG/dalvikvm(675): GC freed 44 objects / 1800
bytes in 151ms
09-29 15:36:15.507: DEBUG/dalvikvm(118): GC freed 3 objects / 72 bytes
in 143ms
09-29 15:36:15.527: DEBUG/dalvikvm(92): GC freed 1539 objects / 70560
bytes in


My java code is:

package com.db;

import java.util.ArrayList;

import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;

public class DataBaseWork extends Activity {
        private final String MY_DATABASE_NAME = "LoginDB";
    private final String MY_DATABASE_TABLE = "Login1";
    private final String tag="Niketa";

    public void onCreate(Bundle icicle) {

         ArrayList<String> results = new ArrayList<String>();
         SQLiteDatabase myDB = null;
         try {

              /* Create the Database (no Errors if it already exists)
              this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE,
              Log.i(tag,"database created");

              /* Open the DB and remember it */

              myDB = this.openDatabase(MY_DATABASE_NAME, null);
              Log.i(tag,"database opened ");

              /* Create a Table in the Database. */
              myDB.execSQL("CREATE TABLE IF NOT EXISTS "
                                  + "LoginDB.Login1"
                                  + " (UserNm TEXT, PassWd TEXT)"
              Log.i(tag,"table created ");
          /*    catch(SQLException e1)
                  Log.i(tag,"SQL EXception"+e1);

              catch(Exception e)

            /*  catch(SQLiteException se)
                  Log.i(tag,"SQLite Error--------"+se);
              /* Add two DataSets to the Table. */
              myDB.execSQL("INSERT INTO "
                                  + MY_DATABASE_TABLE
                                  + " (UserNm, PassWd)"
                                  + " VALUES ('abc', 'def');");
              Log.i(tag,"value inserted ");

              /* Query for some results with Selection and Projection.
              Cursor c = myDB.rawQuery("SELECT UserNm,PassWd" +
                                       " FROM " + MY_DATABASE_TABLE
                                       + ";",
              Log.i(tag,"value seleted ");

              /* Get the indices of the Columns we will need */
              int firstNameColumn = c.getColumnIndex("UserNm");
              int ageColumn = c.getColumnIndex("PassWd");

              /* Check if our result was valid. */
              if (c != null) {
                   /* Check if at least one Result was returned. */
                  if (c.isFirst()) {
                        int i = 0;

                        do {

                             String firstName =
                             int age = c.getInt(ageColumn);
                             String ageColumName =

                             results.add("" + i + ": " + firstName
                                            + " (" + ageColumName + ":
" + age + ")");
                        } while (c!=null);
         catch (Exception e)
              if (myDB != null)
         this.setListAdapter(new ArrayAdapter<String>(this,
                 android.R.layout.simple_list_item_1, results));

        private void setListAdapter(ArrayAdapter<String> arrayAdapter)

        private SQLiteDatabase openDatabase(String my_database_name2, Object
                return null;

        private void createDatabase(String my_database_name2, int i,
                        int modePrivate, Object object)



2. Customizing preferences editor

I have a preference setting that I need to customize so that the preference
will only accept ints.
The way I understand this is that I specify the android:dialogLayout with
the name of my custom layout:

This is my customized EditText: it only accepts numbers up to 9999.
<?xml version="1.0" encoding="UTF-8"?>

android:hint="Enter distance (max 9999)"
This works and shows up correctly.

I do not do anything else and my activity simply loads the XML resource.

The problem is that if I do specify my custom editor the data from the user
is not automatically saved anymore.
(Removing only the line with the dialogLayout makes it save as expected, so
that is correct)

Do I have to specify anything else in the XML to get it saved? Or do I now
have to program this?
(I would have thought that behind the scenes, the editor (whether it is
custom or not) is somehow created by a factory, and then all invocations
happen on the created object, thus making it no difference how the look/feel
of the custom editor is. But that is obviously not how it is done)

Any pointers?



3. How to use mock location in sdk 1.0????

4. ocr for andrion??

5. Log Reading Problem in sdk 0.9

6. Phone Listner API in Android?

7. problems calling Hessian service with HTTP post