On Fri, May 4, 2012 at 4:15 AM, Vikas KM <[email protected]> wrote:

> HI Robert...
>
> Below is the code....
>
> **************************************
>
>             ConnectivityManager CM;
>             CM = (ConnectivityManager)mContext.getSystemService(Context.
> CONNECTIVITY_SERVICE);
>             CM.reportInetCondition(CM.TYPE_MOBILE, 100);
>
> The reportInetCondition is to be used by applications to report their
findings back to CM.  This is not for networks to indicate they are
available.  You didn't indicate who is running this code.



>             NetworkInfo ni;
>              //CM.setNetworkPreference(0);
>             //CM.setMobileDataEnabled(true);
>             //CM.setRadio(0, true);
>
>             SystemClock.sleep(3000);
>
>             Intent broadcastIntent = new Intent();
>             broadcastIntent.setAction("ConnectivityManager.
> CONNECTIVITY_ACTION");
>             if(broadcastIntent != null)
>                 mContext.sendBroadcast(broadcastIntent);


Again, you haven't said who is running this code, but only the CM should
send this broadcast - this is an output from CM, not an input.


>
>
>             ni = CM.getActiveNetworkInfo();
>             if (ni != null && ni.isConnectedOrConnecting())
>                 Slog.e(TAG, "Network Connected .........................");
>             else
>                 Slog.e(TAG, "Network Not Connected
> .......................");
>
>
> ***************************************
>
>
> Is the above code right way of doing?
>
No, I gave some info above, but this is not the right way to do things.


> I want apps to know that there is network.
>
You getActiveNetworkInfo code is good - that should tell you on a working
device if there is a network or not.


>
> I am able to connect to internet through browser but the network icons are
> not up...
>
Are you making this device or is this a commercial device?  If you are
porting to new hardware you need to make sure your MobileDataStateTracker
is working - it is the object that feeds mobile data state info into the
connectivity service.  It should indicate when it is connected and that
will cause the connectivity service to send out broadcast
(CONNECTIVITY_ACTION) indicating it's connected.

R

-- 
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting

Reply via email to