获取系统所有的LocationProvider名称
LocationProvider中最常用的两个GPS_PROVIDER和NETWORK_PROVIDER
程序效果:按下按钮,显示LocationProvider名称
主activity
package com.song;
import java.util.List;
import android.app.Activity;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class C612_GooglemapActivity extends Activity {
/** Called when the activity is first created. */
Button button;
TextView textview;
LocationManager manager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button)findViewById(R.id.button);
textview=(TextView)findViewById(R.id.textview);
manager=(LocationManager)getSystemService(LOCATION_SERVICE);//获取系统location服务
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
List<String> list=manager.getAllProviders();//获取系统所有的LocationProvider名称
String t="";
for (int i = 0; i < list.size(); i++) {
t+=list.get(i)+"\n";
}
textview.setText(t);
}
});
}
}
显示效果