Java Code Examples for com.baidu.location.LocationClient#registerLocationListener()
The following examples show how to use
com.baidu.location.LocationClient#registerLocationListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaiduMapSelectPoiFragment.java From BmapLite with GNU General Public License v3.0 | 6 votes |
public void initBaiduSdk() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); }
Example 2
Source File: SocialPublishActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override protected void onCreate(Bundle arg0) { setContentView(R.layout.activity_social_publish); super.onCreate(arg0); imagePath = this.getIntent().getStringExtra("imagePath"); Log.e("imagePath---->>>>.", imagePath); if (TextUtils.isEmpty(imagePath)) { finish(); return; } Uri uri_temp = Uri.fromFile(new File(imagePath)); // 第一张图片要特别注意一下,是传过来的.... getTwoImage(uri_temp, true); lists.add(uri_temp); initView(); // 位置相关 mLocationClient = new LocationClient(this); // 声明LocationClient类 mLocationClient.registerLocationListener(myListener); // 注册监听函数 }
Example 3
Source File: LocationUtil.java From AndroidDemo with MIT License | 6 votes |
public LocationUtil(Context context) { locationClient = new LocationClient(context); locationClient.setLocOption(getOption()); locationClient.registerLocationListener(locationListener = new LocationListener() { @Override public void onReceiveLocation(BDLocation bdLocation) { if (bdListener != null) { locationClient.stop(); bdListener.onReceiveLocation(bdLocation); } } @Override public void onLocDiagnosticMessage(int i, int i1, String s) { if (bdListener != null) { bdListener.onFail(i, s); } } }); }
Example 4
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化地图控件 mapView = (MapView) findViewById(R.id.mapview); mBaiduMap = mapView.getMap(); //初始化定位 mLocationClient = new LocationClient(getApplicationContext()); //初始化定位 initLocation(); //注册监听函数 mLocationClient.registerLocationListener(this); //开始定位,定位完成后,不管是否成功,都会调用上面的监听函数中的方法 mLocationClient.start(); //设置地图的点击事件 setMapListenter(); }
Example 5
Source File: BaiduMapSelectPoiFragment.java From BmapLite with Apache License 2.0 | 6 votes |
public void initBaiduSdk() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); }
Example 6
Source File: WelcomeActivity.java From Social with Apache License 2.0 | 5 votes |
private void locate(){ //发布代码 mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener(myListener); //注册监听函数 initLocation(); //调用前判断网络连接状态 try{ mLocationClient.start(); }catch (Exception e){ e.printStackTrace(); } }
Example 7
Source File: WBNearbyActivity.java From Simpler with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wb_nearby); ButterKnife.bind(this); //声明LocationClient类 mLocationClient = new LocationClient(getApplicationContext()); //注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.setLocOption(BDLocationUtil.getLocationClientOption()); mLocationClient.start(); // 每次刷新微博数 mRefreshCount = BaseSettings.sSettings.refreshCount; mAdapter = new StatusListAdapter(this, null); mSwipeRefresh.setRecyclerViewAndAdapter(mRvStatuses, mAdapter); mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // 刷新 if (TextUtils.isEmpty(mLongitude) || TextUtils.isEmpty(mLatitude)) { mSwipeRefresh.setRefreshing(false); return; } mPage = 1; loadStatuses(1, true); mSwipeRefresh.setRefreshing(true); } }); mSwipeRefresh.setOnLoadingListener(new DSwipeRefresh.OnLoadingListener() { @Override public void onLoading() { if (mPage != 0) { mAdapter.setFooterInfo(getString(R.string.data_loading)); loadStatuses(mPage, false); } } }); }
Example 8
Source File: WeatherService.java From Dainty with Apache License 2.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { mLocationClient = new LocationClient(getApplicationContext()); MyLocationListener myListener = new MyLocationListener(); initLocation(); mLocationClient.registerLocationListener(myListener); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); city = sharedPreferences.getString("cityName", ""); mLocationClient.start(); return super.onStartCommand(intent, flags, startId); }
Example 9
Source File: GpsUtil.java From FoodOrdering with Apache License 2.0 | 5 votes |
/** * 初始化 */ public GpsUtil(Context ctx, BDLocationListener locationListener) { context = ctx; try { mLocationClient = new LocationClient(context.getApplicationContext()); mLocationClient.registerLocationListener(locationListener); //注册监听函数 initLocation(); mLocationClient.start(); } catch (Exception e) { Log.e("GpsUtil error : ", e.getMessage(), e); } }
Example 10
Source File: Activity_FoodDelivery.java From FoodOrdering with Apache License 2.0 | 5 votes |
/** * 定位,获取当前位置信息 */ private void location() { // 声明LocationClient类 mLocationClient = new LocationClient(getApplicationContext()); initLocation(); // 注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.start(); }
Example 11
Source File: TrackerService.java From LocationProvider with Apache License 2.0 | 5 votes |
/** * 注册百度地图定位功能 */ private void initLocationClient() { client = new LocationClient(this); client.setLocOption(getDefaultLocationClientOption()); client.registerLocationListener(mLocationListener); start(); }
Example 12
Source File: MainActivity.java From Mobike with Apache License 2.0 | 5 votes |
private void initMap() { baiduMap = mBaiduMap.getMap(); baiduMap.setMyLocationEnabled(true); mlocationClient = new LocationClient(getApplicationContext()); mlocationClient.registerLocationListener(new MylocationListener()); // mBaiduMap.showScaleControl(false);// 隐藏比例尺控件 mBaiduMap.showZoomControls(false);//隐藏缩放按钮 LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(5000);//设置onReceiveLocation()获取位置的频率 option.setIsNeedAddress(true);//如想获得具体位置就需要设置为true mlocationClient.setLocOption(option); mlocationClient.start(); mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING; baiduMap.setMyLocationConfigeration(new MyLocationConfiguration( mCurrentMode, true, null)); myOrientationListener = new MyOrientationListener(this); //通过接口回调来实现实时方向的改变 myOrientationListener.setOnOrientationListener(new MyOrientationListener.OnOrientationListener() { @Override public void onOrientationChanged(float x) { mCurrentX = x; } }); myOrientationListener.start(); mSearch = RoutePlanSearch.newInstance(); mSearch.setOnGetRoutePlanResultListener(this); initMarkerClickEvent(); }
Example 13
Source File: HomeActivity.java From LoveTalkClient with Apache License 2.0 | 5 votes |
private void initBaiduLocClient() { mLocClient = new LocationClient(this.getApplicationContext()); mLocClient.setDebug(true); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setScanSpan(5000); option.setIsNeedAddress(false); option.setCoorType("bd09ll"); option.setIsNeedAddress(true); mLocClient.setLocOption(option); mLocationListener = new MyLocationListener(); mLocClient.registerLocationListener(mLocationListener); mLocClient.start(); }
Example 14
Source File: LocationActivity.java From VSigner with GNU General Public License v2.0 | 4 votes |
@Override public void initListeners() { mLocationClient = new LocationClient(mContext); mLocationClient.registerLocationListener(mBdLocationListener); }
Example 15
Source File: MapService.java From MapForTour with MIT License | 4 votes |
void initializeService() { /**-------------定位---------------*/ locationListener = new MyLocationListener(); mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener(locationListener); //注册监听函数 LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 int span = 5000; option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的 option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要 option.setOpenGps(true);//可选,默认false,设置是否使用gps option.setLocationNotify(true);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果 option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近” option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到 option.setCoorType("bd09ll"); mLocationClient.setLocOption(option); /**-------------周边雷达---------------*/ //实例化 radarSearchManager = RadarSearchManager.getInstance(); radarNearbyOption = new RadarNearbySearchOption(); radarNearbyOption.pageCapacity(50); radarNearbyOption.sortType(RadarNearbySearchSortType.distance_from_far_to_near); radarNearbyOption.pageNum(0); radarNearbyOption.radius(5000); /**-------------鹰眼轨迹--------------*/ //实例化轨迹服务客户端 lbsTraceClient = new LBSTraceClient(getApplicationContext()); // 设置定位模式 lbsTraceClient.setLocationMode(LocationMode.High_Accuracy); //位置采集周期 int gatherInterval = 5; //打包周期 int packInterval = 30; //设置位置采集和打包周期 lbsTraceClient.setInterval(gatherInterval, packInterval); //轨迹服务类型(0 : 不上传位置数据,也不接收报警信息; 1 : 不上传位置数据,但接收报警信息;2 : 上传位置数据,且接收报警信息) traceType = 2; //轨迹监听器 myOnTrackListener = new MyOnTrackListener(); lbsTraceClient.setOnTrackListener(myOnTrackListener); /**-------------地理围栏---------------*/ //OnTrackListener接口的实现类,实现轨迹监听器回调方法 //轨迹服务中地理围栏监听器 myOnGeoFenceListener = new MyOnGeoFenceListener(); //Entity监听器 myOnEntityListener = new MyOnEntityListener(); lbsTraceClient.setOnGeoFenceListener(myOnGeoFenceListener); lbsTraceClient.setOnEntityListener(myOnEntityListener); /**--------------广播------------------*/ mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); myServiceReceiver = new myServiceReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("cc.bitlight.broadcast.service.start"); intentFilter.addAction("cc.bitlight.broadcast.service.stop"); intentFilter.addAction("cc.bitlight.broadcast.track.queryhistorytrack"); intentFilter.addAction("cc.bitlight.broadcast.geofence.query"); intentFilter.addAction("cc.bitlight.broadcast.mytemp"); mLocalBroadcastManager.registerReceiver(myServiceReceiver, intentFilter); }
Example 16
Source File: MainActivity.java From BaiDuMapSelectDemo with Apache License 2.0 | 4 votes |
/** * 初始化定位相关 */ private void initLocation() { // 声明LocationClient类 mLocationClient = new LocationClient(getApplicationContext()); // 利用LocationClientOption类配置定位SDK参数 option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); // 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备; option.setCoorType("bd09ll"); // 可选,设置返回经纬度坐标类型,默认gcj02 // gcj02:国测局坐标; // bd09ll:百度经纬度坐标; // bd09:百度墨卡托坐标; // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标 option.setOpenGps(true); // 可选,设置是否使用gps,默认false // 使用高精度和仅用设备两种定位模式的,参数必须设置为true option.setLocationNotify(true); // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false option.setIgnoreKillProcess(true); // 可选,定位SDK内部是一个service,并放到了独立进程。 // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) option.SetIgnoreCacheException(false); // 可选,设置是否收集Crash信息,默认收集,即参数为false option.setEnableSimulateGps(false); // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false option.setIsNeedLocationDescribe(true); // 可选,是否需要位置描述信息,默认为不需要,即参数为false option.setIsNeedLocationPoiList(true); // 可选,是否需要周边POI信息,默认为不需要,即参数为false option.setIsNeedAddress(true);// 获取详细信息 //设置扫描间隔 // option.setScanSpan(10000); mLocationClient.setLocOption(option); // 注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.start(); }
Example 17
Source File: LocationDelegate.java From FastWaiMai with MIT License | 4 votes |
private void initLocation() { // 声明LocationClient类 使用ApplicationContext mLocationClient = new LocationClient(getProxyActivity().getApplicationContext()); // 利用LocationClientOption类配置定位SDK参数 option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); // 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备; option.setCoorType("bd09ll"); // 可选,设置返回经纬度坐标类型,默认gcj02 // gcj02:国测局坐标; // bd09ll:百度经纬度坐标; // bd09:百度墨卡托坐标; // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标 option.setOpenGps(true); // 可选,设置是否使用gps,默认false // 使用高精度和仅用设备两种定位模式的,参数必须设置为true option.setLocationNotify(true); // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false option.setIgnoreKillProcess(true); // 可选,定位SDK内部是一个service,并放到了独立进程。 // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) option.SetIgnoreCacheException(false); // 可选,设置是否收集Crash信息,默认收集,即参数为false option.setEnableSimulateGps(false); // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false option.setIsNeedLocationDescribe(true); // 可选,是否需要位置描述信息,默认为不需要,即参数为false option.setIsNeedLocationPoiList(true); // 可选,是否需要周边POI信息,默认为不需要,即参数为false option.setIsNeedAddress(true);// 获取详细信息 //设置扫描间隔 // option.setScanSpan(10000); mLocationClient.setLocOption(option); // 注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.start(); }
Example 18
Source File: AddressEditDelegate.java From FastWaiMai with MIT License | 4 votes |
private void initLocation() { // 声明LocationClient类 mLocationClient = new LocationClient(getContext()); // 利用LocationClientOption类配置定位SDK参数 option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); // 可选,设置定位模式,默认高精度 LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备; option.setCoorType("bd09ll"); // 可选,设置返回经纬度坐标类型,默认gcj02 // gcj02:国测局坐标; // bd09ll:百度经纬度坐标; // bd09:百度墨卡托坐标; // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标 option.setOpenGps(true); // 可选,设置是否使用gps,默认false // 使用高精度和仅用设备两种定位模式的,参数必须设置为true option.setLocationNotify(true); // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false option.setIgnoreKillProcess(true); // 可选,定位SDK内部是一个service,并放到了独立进程。 // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) option.SetIgnoreCacheException(false); // 可选,设置是否收集Crash信息,默认收集,即参数为false option.setEnableSimulateGps(false); // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false option.setIsNeedLocationDescribe(true); // 可选,是否需要位置描述信息,默认为不需要,即参数为false option.setIsNeedLocationPoiList(true); // 可选,是否需要周边POI信息,默认为不需要,即参数为false option.setIsNeedAddress(true);// 获取详细信息 //设置扫描间隔 // option.setScanSpan(10000); mLocationClient.setLocOption(option); // 注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.start(); }
Example 19
Source File: FakeWeiBoActivity.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
private void initLocationAndSearch() { //location mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener(this); //注册监听函数 LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy );//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系 int span = 1000; option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的 option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要 option.setOpenGps(true);//可选,默认false,设置是否使用gps option.setLocationNotify(true);//可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果 option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近” option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到 option.setIgnoreKillProcess(false);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集 option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤GPS仿真结果,默认需要 mLocationClient.setLocOption(option); //search mPoiSearch = PoiSearch.newInstance(); mPoiSearch.setOnGetPoiSearchResultListener(new MyPoiSearchListener()); mNearbySearchOption = new PoiNearbySearchOption() .radius(5000) .pageNum(1) .pageCapacity(20) .sortType(PoiSortType.distance_from_near_to_far); //////////////// mGeoCoder = GeoCoder.newInstance(); mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() { @Override public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) { Log.e(TAG, "onGetGeoCodeResult: " + geoCodeResult.toString()); } @Override public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) { Log.e(TAG, "onGetReverseGeoCodeResult: " + reverseGeoCodeResult.toString()); } }); }
Example 20
Source File: MainActivity.java From BS-Weather with Apache License 2.0 | 4 votes |
@Override public void initView() { setContentView(R.layout.acticity_main); Toolbar toolbar = (Toolbar)findViewById(R.id.tool_bar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null){ actionBar.setDisplayShowTitleEnabled(false); } // 初始化各种控件 weatherLayout = (ScrollView)findViewById(R.id.weather_layout); titleCity = (TextView)findViewById(R.id.title_city); forecastLayout = (LinearLayout)findViewById(R.id.forecast_layout); mainLayout = (LinearLayout) findViewById(R.id.main_layout); // weather_now degreeText = (TextView)findViewById(R.id.degree_text); weatherInfoText = (TextView)findViewById(R.id.weather_info_text); weaherNowLayout = (RelativeLayout)findViewById(R.id.weather_now_layout); updateTimeText = (TextView)findViewById(R.id.update_time_text); // weather_hour hourDegree = (TextView)findViewById(R.id.hour_degree); hourText = (TextView)findViewById(R.id.hour_text); hourTime = (TextView)findViewById(R.id.hout_time); recyclerView = (RecyclerView)findViewById(R.id.weather_hourly); hourAdapter = new HourAdapter(hourList); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(hourAdapter); // weather_aqi aqiText = (TextView)findViewById(R.id.aqi_text); pm25Text = (TextView)findViewById(R.id.pm25_text); coText = (TextView)findViewById(R.id.co_text); o3Text = (TextView)findViewById(R.id.o3_text); pm10Text = (TextView)findViewById(R.id.pm10_text); so2Text = (TextView)findViewById(R.id.so2_text); // weather_suggestion comfortText = (TextView)findViewById(R.id.comfort_text); carWashText = (TextView)findViewById(R.id.car_wash_text); sportText = (TextView)findViewById(R.id.sport_text); uvText = (TextView)findViewById(R.id.uv_text); clothesText = (TextView)findViewById(R.id.clothes_text); coldText = (TextView)findViewById(R.id.cold_text); comfortBtn = (Button)findViewById(R.id.comfort_button); carWashBtn = (Button)findViewById(R.id.car_wash_button); sportBtn = (Button)findViewById(R.id.sport_button); uvBtn = (Button)findViewById(R.id.uv_button); clothesBtn = (Button)findViewById(R.id.clothes_button); coldBtn = (Button)findViewById(R.id.cold_button); // LBS mlocationClient = new LocationClient(getApplicationContext()); mlocationClient.registerLocationListener(new MyLocationListener()); if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION); } if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.READ_PHONE_STATE); } if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (!permissionList.isEmpty()){ String[] permissions = permissionList.toArray(new String[permissionList.size()]); ActivityCompat.requestPermissions(MainActivity.this, permissions, 1); } swipeRefresh = (SwipeRefreshLayout)findViewById(R.id.swipe_refresh); swipeRefresh.setColorSchemeColors(getResources().getColor(R.color.colorAccent)); }