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);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
@SuppressLint("MissingPermission")
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
latiatual = location.getLatitude();
longatual = location.getLongitude();
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() {...}
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);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
@SuppressLint("MissingPermission")
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
latiatual = location.getLatitude();
longatual = location.getLongitude();
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(){
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() {...}
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() {...}
Como fazer para o executar o metodo getCidade() com o asynctask, e retornar o valor da string cidade para utilizar em outro metodo?
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);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
@SuppressLint("MissingPermission")
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
latiatual = location.getLatitude();
longatual = location.getLongitude();
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(){
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() {...}
}
lang-java