Android使用高德地图地理围栏定位自动发送短信

更新时间:2023-07-18 17:11:57 阅读: 评论:0

Android使⽤⾼德地图地理围栏定位⾃动发送短信功能点:
使⽤⾼德地图实现地理围栏功能
可设置⼿机号和短信间隔,设置后间隔发送当前位置
可地图选点设置地理围栏
离开进⼊地理围栏会有相应短信提醒(设置⼿机号并获取权限后)
关键代码
public class MainActivity extends BaActivity
implements NavigationView.OnNavigationItemSelectedListener,View.OnClickListener,
GeoFenceListener,
AMap.OnMapClickListener,
LocationSource,
AMapLocationListener,
CompoundButton.OnCheckedChangeListener {
private View lyOption;
private TextView tvGuide;
private TextView tvResult;英语字典下载
private EditText etRadius;
private CheckBox cbAlertIn;
private CheckBox cbAlertOut;
private CheckBox cbAldertStated;
private Button btAddFence;
private Button btOption;
private AMapLocationClient mlocationClient;
private LocationSource.OnLocationChangedListener mListener;
private AMapLocationClientOption mLocationOption;
private MapView mMapView;
private AMap mAMap;
// 中⼼点坐标
private LatLng centerLatLng = null;
// 中⼼点marker
private Marker centerMarker;
private BitmapDescriptor ICON_YELLOW = BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW);
private BitmapDescriptor ICON_RED = BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED);
private MarkerOptions markerOption = null;
private List<Marker> markerList = new ArrayList<Marker>();
// 当前的坐标点集合,主要⽤于进⾏地图的可视区域的缩放
private LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
// 地理围栏客户端
private GeoFenceClient fenceClient = null;
// 要创建的围栏半径
private float fenceRadius = 0.0F;
// 触发地理围栏的⾏为,默认为进⼊提醒
private int activatesAction = GeoFenceClient.GEOFENCE_IN;
// 地理围栏的⼴播action
private static final String GEOFENCE_BROADCAST_ACTION = "und";
// 记录已经添加成功的围栏
private HashMap<String, GeoFence> fenceMap = new HashMap<String, GeoFence>();
private View map_top;
@Override
protected void onCreate(Bundle savedInstanceState) {
tContentView(R.layout.activity_main);
requestPermission();
initView();
initMap(savedInstanceState);
}
private void requestPermission() {
.tPermissions(Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE)
.build(),
new AcpListener() {
@Override
public void onGranted() {
}
@Override
public void onDenied(List<String> permissions) {
ToastUtil.show(MainActivity.this,"权限不够,应⽤可能会出现问题");
}
});
}
private void initView() {在线英语翻译器
Toolbar toolbar = (Toolbar) findViewById(lbar);
tSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.tOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ndMessage();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_clo);        drawer.addDrawerListener(toggle);
valvestoggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.tNavigationItemSelectedListener(this);
View headerView = HeaderView(0);
TextView ur = (TextView) headerView.findViewById(R.id.ur_textview);
String urid = String(ConstantValue.USER_LOGIN_INFO, "");
ur.append(urid+"");
}
private void ndMessage() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!
= PackageManager.PERMISSION_GRANTED) {
showMissingPermissionDialog();
}el{
//
startMessage();
}
saint
}
private void showMissingPermissionDialog() {
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);        builder.tTitle(ifyTitle);
builder.tMessage(ifyMsg);
// 拒绝, 退出应⽤
builder.tNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.tPositiveButton(ing,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
kaixing
startAppSettings();
}
});
builder.tCancelable(fal);
builder.show();
}
private void startMessage() {
handler.post(runnable);
}
private int ndMessageDelay = 60000;
Runnable runnable=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//要做的事情
handler.postDelayed(this, 60000);
nd("定位成功 ");
}
};
private void nd(String message) {
if(TextUtils.isEmpty(phone)) {
ToastUtil.show(this,"您还没有设置⼿机号,请在侧滑菜单中设置⼿机号后重试!");吸血鬼日记第二季在线观看
return;
幽灵兰花图片
}
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
ToastUtil.show(this,"您没有获得发送短信的权限");
}el{
SmsManager smsManager = Default();
Log.e("tag",""+currentLocation.length());
smsManager.ndTextMessage(phone,"",message+currentLocation+"",null,null);            ToastUtil.show(this,"发送位置成功");
ToastUtil.show(this,"发送位置成功");
}
}
/**
*  启动应⽤的设置
*
* @since 2.5.0
*
*/
conversation
private void startAppSettings() {
Intent intent = new Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.tData(Uri.par("package:" + getPackageName()));
startActivity(intent);
}
private void initMap(Bundle savedInstanceState) {
// 初始化地理围栏
fenceClient = new GeoFenceClient(getApplicationContext());
tvResult = (TextView)findViewById(R.id.tv_result);
tvResult.tVisibility(View.GONE);
showSetMapDialog = new Dialog(this);
View view = LayoutInflater.from(this).inflate(R.layout.plugin_geofence_option, null);        showSetMapDialog.tContentView(view);
map_top = view.findViewById(R.id.map_top);
lyOption = view.findViewById(R.id.ly_option);
btAddFence = (Button) view.findViewById(R.id.bt_addFence);
btOption = (Button) view.findViewById(R.id.bt_option);
tvGuide = (TextView) view.findViewById(R.id.tv_guide);
etRadius = (EditText) view.findViewById(_radius);
cbAlertIn = (CheckBox) view.findViewById(R.id.cb_alertIn);
cbAlertOut = (CheckBox) view.findViewById(R.id.cb_alertOut);
cbAldertStated = (CheckBox) view.findViewById(R.id.cb_alertStated);
mMapView = (MapView) findViewById(R.id.map);
markerOption = new MarkerOptions().draggable(true);
init();
String urname = String(ConstantValue.USER_LOGIN_INFO,"");
List<Ur> urs = DataSupport.where("urname = ? ", urname).find(Ur.class);
if (urs!=null && urs.size()>0) {
try{
Ur ur = (0);
phone = ur.getSendMessagePhone();
ndMessageDelay = Integer.SendMessageDelay());
}catch (Exception e) {
}
}
}
private Dialog showSetMapDialog;
private void showSetMapDialog() {
if(showSetMapDialog.isShowing()) {
showSetMapDialog.dismiss();
}el {
showSetMapDialog.show();
}
}
@Override
public void onBackPresd() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.cloDrawer(GravityCompat.START);
} el {
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().u.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = ItemId();
if (id == R.id.action_zhuxiao) {
SpUtil.putInt(ConstantValue.USER_LOGIN_INFO,0);
ToastUtil.show(this,"已注销当前帐号,请重新登录");
startActivity(new Intent(this, LoginActivity.class));
finish();
return true;
}
if(id==R.id.action_exit) {
finish();
在线法医return true;
}
OptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = ItemId();
if (id == R.id.nav_phone) {
showPhoneDialog();
}el if(id == R.id.nav_weilan) {
showSetMapDialog();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.cloDrawer(GravityCompat.START);
return true;
}
private String phone;
private void showPhoneDialog() {
final EditText et = new EditText(this);
et.tHint("11位⼿机号");
if(!TextUtils.isEmpty(phone)) {
et.tText(phone);shall
}
final EditText et1 = new EditText(this);
et1.tHint("发送短信间隔(s)");
et1.tInputType(InputType.TYPE_CLASS_NUMBER);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.addView(et);
linearLayout.addView(et1);
linearLayout.tOrientation(LinearLayout.VERTICAL);
new AlertDialog.Builder(this).tTitle("请输⼊⼿机号和短信间隔")
.tView(linearLayout)
.tPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String input = et.getText().toString();
if (input.equals("")) {
Toast.makeText(getApplicationContext(), "⼿机号不能为空!" + input, Toast.LENGTH_LONG).show();                        }
el {

本文发布于:2023-07-18 17:11:57,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/181361.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:围栏   设置   地理   短信   机号   发送
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图