>
public void Salvar_Click(View view) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location location = locationManager.getLastKnownLocation(provider);
la = location.getLatitude();
lo = location.getLongitude();
SQLiteDatabase db = openOrCreateDatabase("vendas.db", Context.MODE_PRIVATE, null);
Spinner spProdutos = (Spinner)findViewById(R.id.spProdutos);
SQLiteCursor dados = (SQLiteCursor)spProdutos.getAdapter().getItem(spProdutos.getSelectedItemPosition());
ContentValues ctv = new ContentValues();
ctv.put("produto", dados.getInt(0));
ctv.put("preco", dados.getDouble(2));
ctv.put("la", la);
ctv.put("lo", lo);
if(db.insert("vendas", "_id", ctv) > 0){
Toast.makeText(getBaseContext(), "Sucesso", Toast.LENGTH_LONG).show();
}
}
Patrick
Qual erro gerado?
Se nao aparece erro ao clicar no salvar...
acredito que o perimission no manifest nao foi realizado.... e isso faz com que ele entre no if e realiza o return.
tenta colocar no AndroidManifest.xml:
[XML]
[/XML]
[XML]
[/XML]