Splashpage
Splashpage
Splashpage
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SeekBar;
import java.util.Timer;
import java.util.TimerTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_slapsh);
}
},4000);
}
activity_main2.xml
<Button android:id="@+id/buttonstartprog1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start"
android:layout_marginTop="50dp" />
<Button android:id="@+id/buttonstopprog1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop"/>
<TextView android:id="@+id/textViewtimer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textSize="34sp"/>
<ImageView
android:layout_width="400dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@mipmap/image8" />
</LinearLayout>
activity_mani.java
package com.example.myapplication;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.util.Timer;
import java.util.TimerTask;
Timer timer;
MyTimerTask myTimerTask;
int a=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//EdgeToEdge.enable(this);
setContentView(R.layout.activity_main2);
b1 =(Button) findViewById(R.id.buttonstartprog1);
b2 =(Button) findViewById(R.id.buttonstopprog1);
e1 =(TextView) findViewById(R.id.textViewtimer1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//create method
getlocation();
try
{
a=0;
timer = new Timer();
myTimerTask = new MyTimerTask();
timer.schedule(myTimerTask, 1000, 1000);
}
catch(Exception w){
Toast.makeText(getApplication(),
w.toString() ,Toast.LENGTH_LONG).show();
}
}
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timer.cancel();
}
});
void getval()
{
a=a+1;
if(a>=60)
{
a=0;
if( gps.canGetLocation()){
try {
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
double Speedval = gps.getSpeed();
String latitudestr = Double.toString(latitude);
String longitudestr = Double.toString(longitude);
String Speedudestr = Double.toString(Speedval);
Toast.makeText(getBaseContext(),latitudestr+",
"+longitudestr+", "+Speedudestr,Toast.LENGTH_LONG).show();
//(t1.getText().toString(), SMSval);
}
catch(Exception ee)
{
Toast.makeText(getApplicationContext(),
"GPS faild, please try again later!",
Toast.LENGTH_LONG).show();
}
}
e1.setText(Integer.toString(a));
}
}
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
GPSTracker(Context context) {
this.mContext = context;
getLocation();
}
//bind service
locationManager = (LocationManager)
mContext.getSystemService(LOCATION_SERVICE);
if (isNetworkEnabled) {
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
android.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;
}
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
}
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Speedval=location.getSpeed();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
* */
public void stopUsingGPS(){
if( locationManager != null){
locationManager.removeUpdates(GPSTracker.this);
}
}
/**
* Function to get latitude
* */
public double getLatitude(){
if( location != null){
latitude = location.getLatitude();
}
return latitude;
}
/**
* Function to get longitude
* */
public double getLongitude(){
if(location != null){
longitude = gps.getLongitude();
}
return longitude;
}
/**
* Function to get longitude
*/
public double getSpeed(){
if(location != null){
/**
* Function to check GPS/wifi enabled
* @return boolean
* */
public boolean canGetLocation() {
return this.canGetLocation;
}
@Override
public void onLocationChanged(Location location) {
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}