Question: Hello, can you please add to my gps code on android studio that uses api 2 7 . I sent it to 3 experts and

Hello, can you please add to my gps code on android studio that uses api 27. I sent it to 3 experts and none of them did what i wanted. I will send you my code of mainactivity.java and I want you to add to my app, right now it can only record the ip adress but I want you to add an option to tell the user to add the country they went to and to rate it out of 5 stars and tweak the code to display past ip locations and star rating aka permanent database. Please make a colorful xml code for the ui. Please dont overthink it, and make it simple as long as it has all of the above functions I am ok with what it looks like
mainactivity.java:
package com.example.simplegpsapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private TextView locationTextView;
private LocationManager locationManager;
private final ArrayList locationList = new ArrayList<>();
private ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationTextView = findViewById(R.id.locationTextView);
Button recordLocationButton = findViewById(R.id.recordLocationButton);
Button viewLocationsButton = findViewById(R.id.viewLocationsButton);
ListView locationListView = findViewById(R.id.locationListView);
// Initialize Location Manager
locationManager =(LocationManager) getSystemService(LOCATION_SERVICE);
// Set up ListView adapter
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, locationList);
locationListView.setAdapter(adapter);
// Record location button functionality
recordLocationButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
getLocation();
}
});
// View saved locations button functionality
viewLocationsButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
adapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "Showing saved locations", Toast.LENGTH_SHORT).show();
}
});
}
private void getLocation(){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
return;
}
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, new LocationListener(){
@Override
public void onLocationChanged(@NonNull Location location){
String locationText = "Lat: "+ location.getLatitude()+", Lon: "+ location.getLongitude();
locationTextView.setText(locationText);
locationList.add(locationText);
Toast.makeText(MainActivity.this, "Location Recorded", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){}
@Override
public void onProviderEnabled(@NonNull String provider){}
@Override
public void onProviderDisabled(@NonNull String provider){}
}, null);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!