compile files('libs/BaiduLBS_Android.jar')
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<!-- 这个权限用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 这个权限用于访问GPS定位 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- 用于读取手机当前的状态 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 访问网络,网络定位需要上网 -->
<uses-permission android:name="android.permission.INTERNET"/>
//自己写 android:name=".application.MyApplication"
<application
android:name=".application.MyApplication"
android:allowBackup="true">
package net.bwie.baidumap.application; import android.app.Application; import com.baidu.mapapi.SDKInitializer; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); //在使用SDK各组件之前初始化context信息,传入ApplicationContext //注意该方法要再setContentView方法之前实现 SDKInitializer.initialize(getApplicationContext()); } }
package net.bwie.baidumap.activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import net.bwie.baidumap.R; public class BaseMapActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base_map); } }
package net.bwie.baidumap.activity; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import net.bwie.baidumap.R; public class MainActivity extends AppCompatActivity implements View.OnClickListener { protected Button mBaseMapBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.activity_main); initView(); } @Override public void onClick(View view) { Intent intent = new Intent(); if (view.getId() == R.id.base_map_btn) { intent.setClass(this, BaseMapActivity.class); } startActivity(intent); } private void initView() { mBaseMapBtn = (Button) findViewById(R.id.base_map_btn); mBaseMapBtn.setOnClickListener(MainActivity.this); } }