永发信息网

android L怎么实现增加群组功能,最好是源码,谢谢!!

答案:2  悬赏:10  手机版
解决时间 2021-01-21 19:26
  • 提问者网友:骑士
  • 2021-01-21 12:34
android L怎么实现增加群组功能,最好是源码,谢谢!!
最佳答案
  • 五星知识达人网友:神的生死簿
  • 2021-01-21 14:11
此代码为实现android L增加群组功能Location功能的简单封装。

package arui.csdn.net;

源码打印?

import static
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle;

public class LocationUtil {

public static boolean isEnabled(Context context) {

LocationManager mLocationManager = (LocationManager) context

.getSystemService(Context.LOCATION_SERVICE);

if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

return true;

}

if (mLocationManager

.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

return true;

}

return false;

}

public static void startLocationService(Context context) {

LocationManager mLocationManager = (LocationManager) context

.getSystemService(Context.LOCATION_SERVICE);

mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

1000L, 10, mLocationListener);

mLocationManager.requestLocationUpdates(

LocationManager.NETWORK_PROVIDER, 1000L, 10,

mLocationListener);

}

public static void stopLocationService(Context context) {

LocationManager mLocationManager = (LocationManager) context

.getSystemService(Context.LOCATION_SERVICE);

mLocationManager.removeUpdates(mLocationListener);

}

public static Location getLocationByGPS(Context context) {

LocationManager mLocationManager = (LocationManager) context

.getSystemService(Context.LOCATION_SERVICE);

Location location = mLocationManager

.getLastKnownLocation(LocationManager.GPS_PROVIDER);

return location;

}

public static Location getLocationByNetwork(Context context) {

LocationManager mLocationManager = (LocationManager) context

.getSystemService(Context.LOCATION_SERVICE);

Location location = mLocationManager

.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

return location;

}

public static void openLocationSetting(Activity act, int requestCode) {

act.startActivityForResult(new Intent(ACTION_LOCATION_SOURCE_SETTINGS),

requestCode);

}

private static final LocationListener mLocationListener = new
LocationListener() {

public void onLocationChanged(Location location) {

// 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发

System.out.println("onLocationChanged:" + location.getLatitude());

}

public void onProviderDisabled(String provider) {

// Provider被disable时触发此函数,比如GPS被关闭

System.out.println("onProviderDisabled:" + provider);

}

public void onProviderEnabled(String provider) {

// Provider被enable时触发此函数,比如GPS被打开

System.out.println("onProviderEnabled:" + provider);

}

public void onStatusChanged(String provider, int status, Bundle extras)
{

// Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数

System.out.println("onStatusChanged:" + status);

}

};

}

需要增加权限:

android:name="android.permission.ACCESS_FINE_LOCATION" />

android:name="android.permission.ACCESS_COARSE_LOCATION" />
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯