1
public class CadAnuncio extends AppCompatActivity {
LocationManager locationManager;
private Button btnSalvar;
private DatabaseReference databaseAnuncio, databaseUsuario;
private String uid, url, url02, url03, url04, url05, url06, nome, idade, sexo, etnia,cabelo, atendo, viagem, tFisico, valor, fone, descricao, cidade;
private ImageView imgPrincipal, foto02, foto03, foto04, foto05, foto06;
private FirebaseAuth mAuth;
private Uri resultUri, resultUri02, resultUri03, resultUri04, resultUri05, resultUri06;
private Spinner spIdade, spSexo, spEtnia, spCabelo, spAtendo, spViagem, spFisico;
private EditText txtDescricao, txtFone, txtNome, txtValor;
private TextView latitudea, longitudea;
Double latiatual, longatual;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cad_anuncio);
getCidade();
// Solicitar permissão de acesso à galeria e à localização
String[] permissoes = new String[]{
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
};
Permissoes.validate(this, 0, permissoes);
txtNome = findViewById(R.id.txtNome);
txtValor = findViewById(R.id.txtValor);
txtFone = findViewById(R.id.txtFone);
txtDescricao = findViewById(R.id.txtDescricao);
spIdade = findViewById(R.id.spIdade);
spSexo = findViewById(R.id.spSexo);
spEtnia = findViewById(R.id.spEtnia);
spCabelo = findViewById(R.id.spCabelo);
spAtendo = findViewById(R.id.spAtendo);
spViagem = findViewById(R.id.spViagem);
spFisico = findViewById(R.id.spFisico);
imgPrincipal = findViewById(R.id.imgPrincipalAnuncio);
foto02 = findViewById(R.id.foto02);
foto03 = findViewById(R.id.foto03);
foto04 = findViewById(R.id.foto04);
foto05 = findViewById(R.id.foto05);
foto06= findViewById(R.id.foto06);
btnSalvar = findViewById(R.id.btnSalvar);
mAuth = FirebaseAuth.getInstance();
uid = mAuth.getCurrentUser().getUid();
databaseUsuario = FirebaseDatabase.getInstance().getReference("Usuarios").child("Anunciantes").child(uid);
databaseAnuncio = FirebaseDatabase.getInstance().getReference("Anuncios").child(cidade).child(uid);
btnSalvar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
salvaDadosAnuncio();
goMeuPerfil();
finish();
}
});
getDadosAnuncio();
imgPrincipal.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 1910);
}
});
foto02.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 2);
}
});
foto03.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 3);
}
});
foto04.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 4);
}
});
foto05.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 5);
}
});
foto06.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.PICK");
intent.setType("image/*");
startActivityForResult(intent, 6);
}
});
}
private void getCidade(){
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
@SuppressLint("MissingPermission")
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
latiatual = location.getLatitude();
longatual = location.getLongitude();
Verso.getInstance().setup(CadAnuncio.this);
GeoInfo geoInfo = Verso.getInstance().getGeoInfo(latiatual, longatual);
cidade = geoInfo.getCityName();
}
private void salvaDadosAnuncio() {...}
public void onActivityResult(int requestCode, int resultCode, Intent data) {...}
private void goMeuPerfil() {...}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {...}
public void getDadosAnuncio() {...}
}
It worked, but it is still very time consuming process, and the app screen keeps getting dark during the search of the logged user’s city, but this is another story... in case I want to use the value of the string city in two different activities which the best way?
– Filipe Araujo Gomes
Which of the methods you used?
– Lennoard Silva
The first one you suggested.
– Filipe Araujo Gomes