PORT SMS IMPLMENTATION IN ANDROID

 Port sms working principle:

           Application port numbers can be used in SMS messages to deliver a particular SMS to an application on a mobile phone. The application port addressing feature of SMS messages allows specifying a source port and a destination port number for an SMS message .

             The Port sms working principle is shown below in the diagram

                            1.1 port sms working principle

 Receiving Message      

 To receive a binary message we create broadcast receiver with android.intent.action.DATA_SMS_RECEIVED. We also need to specify additional parameters, the receiving data port and the scheme.

  For reference:

 <receiver

           android:name=”com.tam.mpos.notification.NotificationReceiver

           android:exported=”true” >

           <intent-filter android:priority=”999” >

               <action android:name=”android.intent.action.DATA_SMS_RECEIVED” />

               <data android:port=”8900” />

               <data android:scheme=”sms” />

           </intent-filter>

 </receiver>

additionally we need to add permissions to receive and to read sms.

 Permissions:

  <uses-permission android:name=”android.permission.READ_SMS” />

  <uses-permission android:name=”android.permission.RECEIVE_SMS” />

Notification Database Structure

            Once the application received the message from server we are storing internally into the database.

Notification Table:

Database name: Operatorlist.db

     Table Name: Notification Table

thread_id

address

date

read

body

service_centre

1

919840901970

12/10/2012

1

Welcome to Yeldi Ara !!

+919840011016

2

919840901970

12/10/2012

1

Hello Merchant !!

+919840011016

3

919840901970

23/11/2012

0

Plese Update your Yeldi App!!

+919840011016

4

919840901970

30/11/2012

1

You reached 1000 transactions.Thanks be a part of Yeldi !!

+919840011016

                                                 Notification Table Structure.

      Note:

             The field read have two status 0 and 1 , 0 for unread message

            1 for read message.

Notification Receiver Class: Continue reading

Android Activity Life cycle

Hi Today  i am going to explain  about Activity lifecycle in Android with sample application.this is the most basic and will say like a starter for Android Developers.Ok will go for a order now.Cheers Dev’s !!.

Activity:

Activity – represents the presentation layer of an Android application, e.g. a screen which the user sees. An Android application can have several activities and it can be switched between them during runtime of the application.

Each activity will be stacked or maintaining in the ActivityManager.Until the Activities are Destroyed.

Activity states /Life Cycle:

Each activity have different states as below,Totally seven (7) states the Activity will maintain in their lifecycle .

1.onCreate().

2.onStart().

3.onPause().

4.onResume().

5.onStop().

6.onRestart().

7.onDestroy()

Activity Life Cycle A Diagrammatic representation:

ActivityLifecycle

  • When the Activity has started from the intent or from the LAUNCHER Activity .Lets say ActivityA .the following callback methods will be called in the order of onCreate(),onStart(),onResume().

ActivityB started Without Finishing the ActivityA:

Intent intent=new Intent(getApplicationContext(),ActivityB.class);

startActivity(intent);

  • When there is an another activity (ActivityB) call is happening from the ActivityA.the ActivityA will go to the States called onStop(),onPause() and the ActivityA will be in the background and goes to inVisible.And the ActivityB will follows the onCreate(),onStart() and onResume() state.on Stack or ActivityManger will have the ActivityB on the Top.See the below diagram for reference.

Activity stack

  • If suppose user pressed back button when the Current ActivityB is displaying in the Screen/Device.the ActivityA goes to Visible and the following states will be called onResume() and onRestart().Now the ActivityA will be on Top of the stack.

ActivityB started by Finishing the ActivityA:

  • The above states describe when we are starting a activity(ActivityB) from the currentActivity(ActivityA) without calling finish() method.

Intent intent=new Intent(getApplicationContext(),ActivityB.class);

startActivity(intent);

finish();

  • when We are calling a ActivityB from ActivityA by finishing/Destroying ActivityA.the ActivityA no more in the Stack.so when the user pressing back button from ActivityB the ActivityA No more present in the stack so the Application will be closed without any notification.

ActivityA starting from ActivityB :

 So ActivityA has destroyed by above process.lets start the ActivityA from the ActivityB.so simple

 Intent intent=new Intent(getApplicationContext(),ActivityA.class);

startActivity(intent);finish();

when we are coding like above to start ActivityA. again the ActivityA will be started from the scratch by following callback methods onCreate(),onStart() and onResume().

Note:

This method of starting a activity will consume battery.when the application is running.

Download a Sample Application to explore realtime knowledge.

https://www.box.com/files/0/f/0/1/f_7793960462