Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Sir,

I have designed a mobile Application in J2ME Eclipse 3.7.1 in which the sms listen from a specific port like 5000 now the application ported on Android in which the application sending the sms successfully but when receiving there is no response because through another side the sms are sending on 5000 port plese sir help anyone how I listen sms on a port in android

I am binding the sms receiving code below -
Java
package com.sms;
import java.net.URI;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.widget.Toast;

import com.thread.MainThread;
import com.thread.SMSSync;
import com.util.ConstantClass;
import com.zigbee.ZigbeeActivity;
public class SMSReceiver extends BroadcastReceiver {
	private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
	private SMSSync sync;
	private Context context;
	public SMSReceiver(Context ctx){
		sync = new SMSSync(ctx);
		this.context = ctx;
	}
	
	@Override
	public void onReceive(Context context,final Intent intents){
		if (intents.getAction().equals(SMS_RECEIVED)) {
			new Thread(){
				Context context;
				Thread Set(Context ctx){
					this.context=ctx;
					return this;
			}
		public void run(){
			try{
			SmsManager sms = SmsManager.getDefault();
			Bundle bundle = intents.getExtras();
			/*String uriContent =bundle.getString("port");
			String[] str = uriContent.split(":");
			String strPort = str[str.length-1];
			short Port =  Short.valueOf(strPort, 16);*/
			//if(Port==5000){*/
			if (bundle != null) {
			Object[] pdus = (Object[]) bundle.get("pdus");
			SmsMessage[] messages = new SmsMessage[pdus.length];
			for (int i = 0; i < pdus.length; i++)
			messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
			String msg=null;
			String address = null;
				for (SmsMessage message : messages) {
					 msg = message.getMessageBody();
					 address = message.getOriginatingAddress();
				}
				////////////sending to SMSSync class//////////////
				MainThread th = new MainThread(sync,msg);
				try{
					th.thread.join();
				}catch(Exception e){
					Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
				}
				if(msg.substring(3, 4).equals("2"))
					ConstantClass.isAuditrequestSend = true;
//				sync.smsProcess(msg);
				//Toast.makeText(context, "Message Received Successfully", Toast.LENGTH_SHORT).show();				
			}
//			}
			////////////////after receiving the sms opening the Main Screen./////////////////////
			Intent intent = new Intent(context,ZigbeeActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent);
			
			
		}catch(Exception e){
			Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
		}
		}
	}.Set(context).start();
	}
	}
//}
}

Thanks n regards

Om Parkash Kaushik
Posted
Updated 19-Mar-12 1:16am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900