Problem while sending SMS- Could not connect to cilent socket : connection refused.

by javame_android » Wed, 31 Dec 2008 14:07:03 GMT


Sponsored Links
 Hi,

I am trying to write a simple application for sending SMS. In that one
needs to enter a number and after fetching that number from the
textbox sms should be send to that number. I have tried to implement
that code on emulator. It gives could not connect to client socket:
Connection refused. What is it? Am I missing something?

Hope to get a reply soon.

Thanks & Regards
Sunil
--~--~---------~--~----~------------~-------~--~----~



Problem while sending SMS- Could not connect to cilent socket : connection refused.

by javame_android » Wed, 31 Dec 2008 14:44:00 GMT


 Hi,

Thanks for replying.

You are saying to add permission for internet but I am not using
anything related to internet. I have written a simple application that
just sends message. That is working fine but this problem has come
when trying to implement with GUI. I have added the permission for
sending sms. I want to send SMS on the click event of button. When I
click the button then it gives the error as could not connect to
client socket : connection refused.

Any help would be appreciated.

Thanks & Regards
Sunil




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Problem while sending SMS- Could not connect to cilent socket : connection refused.

by javame_android » Wed, 31 Dec 2008 14:56:55 GMT


 package com.android.hello;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.telephony.gsm.SmsManager;
import android.text.Editable;

public class HelloAndroid extends Activity
{
    final String textMsg = "Hello, Message sent on Click";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        final SmsManager smsManager = SmsManager.getDefault();
        Button button = (Button)findViewById(R.id.ok);
        button.setOnClickListener(new Button.OnClickListener()
        {
                public void onClick(View arg0)
                {
                        EditText editText = (EditText)findViewById(R.id.entry);
                Editable tPhone = editText.getText();
                String numToSendMsg = tPhone.toString();
                smsManager.sendTextMessage(numToSendMsg, null,
textMsg, null, null);
                }
        });
    }
}

Above is the code that I am trying to run. Everything is working fine,
GUI is displayed properly. The problem only comes when I click on
button. I am very new to Android so not getting where I am getting
wrong.

Thanks
Sunil


--~--~---------~--~----~------------~-------~--~----~



Problem while sending SMS- Could not connect to cilent socket : connection refused.

by javame_android » Wed, 31 Dec 2008 16:52:56 GMT


 Hi,

Did what you said but no success. Still the same problem GUI displayed
properly but after entering number in the textbox and pressing the
button it gives on ddms console as could not connect to client
socket : connection refused.

By the way I did what you said but I dont think for sending sms one
has to write uses-permission for receiving sms.
Anyways thanks.

Is there anybody who has encountered same error and can help me out.

Thanks & Regards
Sunil




--~--~---------~--~----~------------~-------~--~----~



Problem while sending SMS- Could not connect to cilent socket : connection refused.

by javame_android » Thu, 01 Jan 2009 13:33:46 GMT


 Hi,

This was solved by calling another activity. It means UI displayed in
one activity and sms sending task achieved in another activity. I dont
know whether this is the way or not but it removed this error.

Sunil





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. OOT: Tsunami

Sudah sampe Sulawesi ya, turut berduka atas musibah Tsunami di Jepang

~ Jus ~
\ MotoblurVerizon wireless powered by Smart \

-- 
===============

2. dispatching key events from dialog to other acivities

Hi,
I am trying to dispatch key-event to other activity from a dialog, I
am trying to add a dialog in WindowManagerSerivce.java file in
frameworks/base/services/java/com/android/server, to display this
dialog i am using the following snippet to get SystemContext


ActivityThread at = ActivityThread.currentActivityThread();
        if (at == null) {
            Looper.prepare();
            at = ActivityThread.systemMain();
        }
        if(at != null){
            sysContext = at.getSystemContext();
            Log.d(TAG, "SystemContext = " + sysContext);
        }
Dialog dialog = new Dialog(sysContext);
 
dialog.setContentView(com.android.internal.R.layout.<my_Custom_layout>);
                dialog.setTitle("Custom Dialog");
                dialog.show();

but i can't able to display the dialog



When i tried to launch activity as a dialog (@android:style/
Theme.Dialog) using intent, for the same, activity is displayed as
dialog. fine, now what i am trying is i want to dispatch keyevent when
you press a button in the dialog displayed, i am using handler to pass
the messages to WindowManagerService, where it will dispatch the
keyevent and even i get the pid of top activity and pass the same to
dispatchKey() method in WindowManagerService.java,  dispatchKey
returns '1' which means the key is dispatched successfully. what
actually i am doing is when you press a button in the dialog, i will
pass a message to handler implemented in WindowManagerService.java
say, DISPATCH_BACK_KEY, and i am able to get proper PID from the
activity manager

packageName =
am.getRunningTasks(1).get(0).topActivity.getPackageName();
List<ActivityManager.RunningAppProcessInfo> processes;
                    processes = am.getRunningAppProcesses();
                    for(ActivityManager.RunningAppProcessInfo info:
processes) {
                        Log.i("Process:", info.processName);
 
if(currentPackageName.equalsIgnoreCase(info.processName)){
                            Log.i(TAG, "Found !");
                            mpid = info.pid; //pid of top Activity
                            muid = 0;
                        }
                    }
public void handleMessage(Message msg) {
switch (msg.what) {

case DISPATCH_BACK_KEY:
 Log.d(TAG, "Dispatching Back_Key");
 code = KeyEvent.KEYCODE_BACK;
 KeyEvent backEvent = new KeyEvent(downTime, eventTime, action, code,
repeatCount, metaState,
  deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
  Log.i(TAG, "PID = " + mpid + ", UID = " +muid);
  result = dispatchKey(backEvent, mpid, muid);
  Log.d(TAG, "Dispatch Key Returns = " + result);
  break;
}

Key is dispatched successfully, but the activity beyond the my-dialog
displayed is still visible. please help me how can i proceed to
dispatch back key to the activity beyond my-dialog..


Thanks in advance

-- 

3. [WTS] Motorola Xoom Wifi + Evdo.

4. How to preserve preferences settings with application update

5. java sous android

6. Make View Selectable in Honeycomb

7. Time Conversion - CST to LST(Local Standard Time)