Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 13
Registered: ‎12-14-2009
My Device: 9000
My Carrier: Idea

Unable to send SMS through custom SMS application.

Hi I am trying to developed a custom SMS application. I got some code snippet from other posts but I am still facing problem implementing the code. I tried two methods:

 

Method 1:

 

public class EnterNumber extends MainScreen {
	LabelField titleEnterNumber = new LabelField("Enter Number",LabelField.ELLIPSIS);
	HorizontalFieldManager hfm2 = new HorizontalFieldManager();
	HorizontalFieldManager hfm3 = new HorizontalFieldManager();
	BasicEditField msgno = new BasicEditField("Enter No:",null,10,TextField.PHONENUMBER);
	
	public EnterNumber(){
		
		setTitle(titleEnterNumber);
				
		
		hfm2.add(msgno);
		
		
		add(new SeparatorField());
		add(hfm2);
		
	}
	protected void makeMenu(Menu menu, int instance){
		menu.add(sendSms);
	}
	
	
	private MenuItem sendSms = new MenuItem("Send",110,10){
			public void run(){
			sendSMS();
		}
	};
	
	public void sendSMS(){
		Dialog.alert("inside sms");
		String address = "sms://"+msgno.getText(); 
		Dialog.alert(address);
		System.out.println(address);
			  
			MessageConnection smsconn = null;   
			  
			try {   
			   smsconn = (MessageConnection) Connector.open(address);   
			  
			   TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE);   
			   txtmessage.setPayloadText("SMS sending suceessfull");   
			  Dialog.alert("Messge is loaded");
			  System.out.println("Messge is loaded");
			   smsconn.send(txtmessage);   
			  Dialog.alert("Message sent");
			  System.out.println("Message sent");
			} catch (Exception t) {   
			   System.out.println(t.getMessage()); 
			   Dialog.alert(t.getMessage());
			   System.out.println(t.getClass().getName());   
			}   
			  
			if (smsconn != null) {   
			   try {   
			      smsconn.close();   
			   } catch (IOException ioe) {   
			      System.out.println(ioe.getMessage());         }   
			}  

	}
}

 

Using this I get an error alert after setPayloadText(): saying "operation prohibited bloacking operation on event despatcher thread".

 

So I used the Method 2 trying to run it in a thread:

 

public class EnterNumber extends MainScreen implements Runnable{
	LabelField titleEnterNumber = new LabelField("Enter Number",LabelField.ELLIPSIS);
	HorizontalFieldManager hfm2 = new HorizontalFieldManager();
	HorizontalFieldManager hfm3 = new HorizontalFieldManager();
	BasicEditField msgno = new BasicEditField("Enter No:",null,10,TextField.PHONENUMBER);
	Thread t;
	public EnterNumber(){
		t = new  Thread(this);
		setTitle(titleEnterNumber);
				
		
		hfm2.add(msgno);
		
		
		add(new SeparatorField());
		add(hfm2);
		
	}
	protected void makeMenu(Menu menu, int instance){
		menu.add(sendSms);
	}
	
	
	private MenuItem sendSms = new MenuItem("Send",110,10){
			public void run(){
			Dialog.alert("inside run");
			t.start();
		}
	};
	
	public void run(){
		Dialog.alert("inside sms");
		String address = "sms://"+msgno.getText(); 
		Dialog.alert(address);
		System.out.println(address);
			  
			MessageConnection smsconn = null;   
			  
			try {   
			   smsconn = (MessageConnection) Connector.open(address);   
			  
			   TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE);   
			   txtmessage.setPayloadText("SMS sending suceessfull");   
			  Dialog.alert("Messge is loaded");
			  System.out.println("Messge is loaded");
			   smsconn.send(txtmessage);   
			  Dialog.alert("Message sent");
			  System.out.println("Message sent");
			} catch (Exception t) {   
			   System.out.println(t.getMessage()); 
			   Dialog.alert(t.getMessage());
			   System.out.println(t.getClass().getName());   
			}   
			  
			if (smsconn != null) {   
			   try {   
			      smsconn.close();   
			   } catch (IOException ioe) {   
			      System.out.println(ioe.getMessage());         }   
			}  

	}
}

 

I only get one alert: "Inside run". After that no sms is sent, no error, no alert, no exception please help.

 

I am using following things for developing the application:

 

  1. I am testing on BB 9000 handsets.
  2. Using blackberry 4.6 plugin for Eclipse.
  3. Error I am getting: Already mentioned with code.
  4. Code: Already given both the implementation techniques.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Unable to send SMS through custom SMS application.

tried with setting Message.setAddress()?


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 13
Registered: ‎12-14-2009
My Device: 9000
My Carrier: Idea

Re: Unable to send SMS through custom SMS application.

yes i have tried that tooo....

 

 

i feel its threading problem....

 

i later tried a new approach trying to launch a new thread in constructor of a new class and tried to send SMS through that but the result was same as METHOD 2.

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Unable to send SMS through custom SMS application.

Did you give a look into SMSdemo app shipped with JDE?


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 13
Registered: ‎12-14-2009
My Device: 9000
My Carrier: Idea

Re: Unable to send SMS through custom SMS application.

Yes i tried SMS sample provided with JDESmiley Sadnot workingSmiley Sad)

 

 

even SMS is not getting send by that.......

 

but I am able to send SMS by using the inbuild messaging service......(the normal metthod to send SMS on any device)

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Unable to send SMS through custom SMS application.

[ Edited ]

Which device, OS  and carrier you are trying it on. If it is CDMA use DatagramConnection.


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 13
Registered: ‎12-14-2009
My Device: 9000
My Carrier: Idea

Re: Unable to send SMS through custom SMS application.

Details:

 

Device->9000  v406..0266 (platform 4.0.0.223).

CLDC 1.1.

MIDP 2.0.

Carrier-> IDEA(gsm).

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Unable to send SMS through custom SMS application.

Not a solution, just a suggestion have you tried with other network, cross check?


Use Search. "Accept Solution" If the problem is resolved.
Highlighted
New Developer
Posts: 13
Registered: ‎12-14-2009
My Device: 9000
My Carrier: Idea

Re: Unable to send SMS through custom SMS application.

Thanks BBDeveloper,

 

I'll try that tooo.....