开发者

How to avoid the issue GPS status -Temporarily unAvailable in my android application

I am writing an android application to get location of my device, It is always showing GPS status as TEMPORARILY UN AVAILABLE, its even not calling Location Changed method even though i am changing location of my mobile, could you please look into the issue with the below code

    ls= (ArrayList<String>)lm.getProviders(false);

    Log.e(""," SIZE "+ls.size());
    sb=new StringBuilder();
    for(int i=0;i<ls.size();i++)
        {Log.e("","Data : "+ls.get(i));
        lp=lm.getProvider(ls.get(i));

        sb.append("\nProvider Name : "+lp.getName());
        sb.append("\nPower Requirement :"+lp.getPowerRequirement());
        sb.append("\nAccuracy : "+lp.getAccuracy()+"\n\n");

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);

        Location location=lm.getLastKnownLocation(ls.get(i));           
        }

    strt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            TextView tv=(TextView)findViewById(R.id.TextView01);
            tv.setText("StarteD :"+sb);

        }
    });

    stop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            TextView tv=(TextView)findViewById(R.id.TextView01);
            tv.setText("STOPPED ys  :"+res);
            Location location=lm.getLastK开发者_开发问答nownLocation(ls.get(1));

            if(location==null)
                Log.e("","location object null");
            try{
            tv.append("\nLogitude: "+location.getLongitude());
            tv.append("\nLattitude: "+location.getLatitude());
            tv.append("\nTime:"+location.getTime());
            tv.append("\nSpeed: "+location.getSpeed());
            tv.append("\n Provider:"+location.getProvider());

            }catch(Exception e){}
        }
    });


}
@Override
public void onLocationChanged(Location location) {
    Log.e("","LocationChandgeD... ");
}
@Override
public void onProviderDisabled(String provider) {
    Log.e("",provider+" DIsabled... ");
}
@Override
public void onProviderEnabled(String provider) {
    Log.e("",provider+" Enabled... ");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    switch (status) {
    case LocationProvider.OUT_OF_SERVICE:
        Toast.makeText(this, "Status Changed: Out of Service",
                Toast.LENGTH_SHORT).show();
        break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
        Toast.makeText(this, "Status Changed: Temporarily Unavailable",
                Toast.LENGTH_SHORT).show();
        break;
    case LocationProvider.AVAILABLE:
        Log.e("", "Status Changed: Available");         
        Toast.makeText(this, "Status Changed: Available",
                Toast.LENGTH_SHORT).show();
        break;
    }

}


Unfortunaitly GPS doesn't work without a clear view of the sky (indoors or around dense coniferous tree coverage). Maybe you should try moving outdoors to test your program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜