Can I force Android to open a network connection on a specified network interface/network type ?

by Graeme » Fri, 06 Mar 2009 19:37:59 GMT


Sponsored Links
 Hi

I have been looking at the ConnectivityManager class documented at
 http://developer.android.com/reference/android/net/ConnectivityManager.html 
.

I would like to know if an Android application can open a network
connection (socket) on a specified network interface [on a device
supporting multiple network interface types WiFi, Cellular, WiMax
etc] ? I am looking for the capability for an application to open a
socket on a given type of network for example
over WiFi network or over 3G Cellular Data network.

If this is possible in Android, how would I code this requirement
within the API Framework ?
The ConnectivityManager enables an application to learn about
available network connections and
currently categorises them as either TYPE_WIFI or TYPE_MOBILE.

There is a member function in the ConnectivityManager class  called
requestRouteToHost(int,int) [see
 http://developer.android.com/reference/android/net/ConnectivityManager.html #requestRouteToHost(int,%20int)]
which "Ensure that a network route exists to deliver traffic to the
specified host via the specified network interface. An attempt to add
a route that already exists is ignored, but treated as successful."
Sounds like this would install an IP routing table entry to reach a
given host via a specified network interface type (WiFi or Mobile).
After calling this would it be sufficient for an application to open a
socket and connect to the desired destination address ?

Or perhaps the application needs to bind() a socket to a local address
of a network interface of the desired type (WiFi or Mobile)

Or by setting a socket-level socket option of SO_DONTROUTE ?

Any help would be appreciated
Thanks
Graeme
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. focus control in compund control?

Hello,

I am trying to create a compound control using a TextView and Seekbar.
I am also trying to keep the SeekBar focused on itself during
View.FOCUS_RIGHT and View.FOCUS_LEFT transitions. If using just a seek
bar by itself I can add android:nextFocusRight(Left) to the layout.xml
which works. But when I pass focus to the seekbar in the compound
control it does not seem to work.

Any ideas on how to constrain the focus of a seek bar in a compound
control to only exit focus on View.FOCUS_UP or View.FOCUS_DOWN?

                         <mvis.pektroller.SeekBarLabeled
                                android:id="@+id/BrightnessBar"
                                android:layout_width="fill_parent"
 
android:layout_height="wrap_content"
                                android:max="100"
android:progress="100"
                                android:nextFocusRight = "@+id/
BrightnessBar">
                            </mvis.pektroller.SeekBarLabeled >

public class SeekBarLabeled extends LinearLayout {

        private static final String TAG = "SeekBarLabeled";

        TextView        textView;
        SeekBar seekBarFocused;

...
        public SeekBarLabeled(Context context, AttributeSet attrs) {
                super(context, attrs);

                LayoutInflater inflater = (LayoutInflater)getContext
().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View view = inflater.inflate(R.layout.seek_bar_labeled, this);

                view.setFocusable(true);
                seekBarFocused = (SeekBar)findViewById(R.id.ValueBar);
                textView = (TextView)findViewById(R.id.ValueText);
        }

        public void onFocusChanged(boolean gainFocus, int direction, Rect
previouslyFocusedRect) {

                if (gainFocus) {
                        textView.setTextColor(Color.WHITE);
                        Log.v(TAG, "onFocusChangeListener() hasFocus.");
                        seekBarFocused.requestFocus();
                } else {
                        textView.setTextColor(Color.LTGRAY);
                        Log.v(TAG, "onFocusChangeListener() !hasFocus.");
                }

                super.onFocusChanged(gainFocus, direction, 
previouslyFocusedRect);
        }
}

-- 

2. Broadcasting Intent from native code

Hi all,

The following I already posted to Android-NDK forum, but i wasn't get
any responses,  Thats why I am posting the same here, by expecting a
help from this forum. Sorry for the duplicate postings.

I am wrote JNI wrapper to broadcast Intent from native code.

But i am facing the following issue.

If i wasn't add any receiver filter for my broadcast action in my
application manifest file(that means i am not receiving the brodcasted
intent from my Application). I am able to broadcast Intents to an
unlimited number. But if I add the broadcast receiver for the action
which i broadcast from my native code, I am able to broadcast only 9
Intents.

Here Each Intent holding maximum of 300 bytes of data as a
parcellable.

Is Android suggest to broadcast Intents from Native code?

Is there any other way to communicate Application from native code
asynchronously?

How does the android framework communicate from native code to JAVA
applications.

Thanks in advance.

Regards,
Anzi

-- 

3. Error to create an AVD - Ignoring add-on

4. Getting a Nexus One

5. How to build a binary dictionary for Latin IME( main.dict ) ??

6. HTC Hero OpenGL Bug

7. BitmapDrawable with unexpected size in Android 2.0.1 WVA854