java三星Galaxy S7崩溃获取位置
我有一个在我的Galaxy S6和我兄弟的Galaxy S4上运行了一年的应用程序
他最近买了一个新的Galaxy S7,当它试图访问定位服务时,应用程序崩溃
我已经在互联网上努力搜索,但我找不到任何关于为什么会发生这种情况的参考资料
他已经打开了定位服务,我已经完成了正确的权限请求(据我所知)
我编写了一个小得多的应用程序,它只访问定位服务,并获得一个在我的S5上运行良好的位置,但当他运行这个裸体应用程序时,它也会在初始执行时立即崩溃
我已包含以下代码,希望有人能帮助我找到问题:
public class MainActivity extends AppCompatActivity implements LocationListener {
static LocationManager locationManager;
public static double currentLat, currentLon;
public static Location location;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setSpeedRequired(true);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
//Acquire a reference to the system Location Manager
String provider;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(criteria, false);
if (locationManager != null) {
if ( ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.removeUpdates(this);
}
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);
location = locationManager.getLastKnownLocation(provider);
currentLat = location.getLatitude();
currentLon = location.getLongitude();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
openMapActivity();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
if (locationManager != null) {
if ( ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.removeUpdates(this);
}
}
locationManager.removeUpdates(this);
}
public void openMapActivity(){
// if bReady is false there hasn't been a new location recorded. Use the last known location to
// place the camera on the map
Intent intent = new Intent(this, MapsActivity.class);
startActivity(intent);
}
}
这是舱单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.daknife.locationtest">
<uses-permission 安卓:name="安卓.permission.ACCESS_COARSE_LOCATION" />
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity
安卓:name=".MainActivity"
安卓:label="@string/app_name"
安卓:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
安卓:name="com.google.安卓.geo.API_KEY"
安卓:value="@string/google_maps_key" />
<activity
安卓:name=".MapsActivity"
安卓:label="@string/title_activity_maps"></activity>
</application>
</manifest>
共 (0) 个答案