├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── MFE Vehicle Tracker.apk ├── app-release.apk ├── build.gradle ├── libs │ ├── apache-httpcomponents-httpclient.jar │ └── apache-httpcomponents-httpcore.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── madeel │ │ └── devicetracker │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── com │ │ │ └── mfe │ │ │ └── madeel │ │ │ └── devicetracker │ │ │ ├── Approve.java │ │ │ ├── GPSTracker.java │ │ │ ├── MainActivity.java │ │ │ ├── MyService.java │ │ │ ├── SplashScreen.java │ │ │ ├── login.java │ │ │ └── register.java │ └── res │ │ ├── drawable │ │ ├── logo.jpg │ │ ├── logo1.jpg │ │ ├── logochange.jpg │ │ ├── logoqurvex.jpg │ │ └── spl.jpg │ │ ├── layout │ │ ├── activity_approve.xml │ │ ├── activity_login.xml │ │ ├── activity_main.xml │ │ ├── activity_register.xml │ │ └── activity_splash_screen.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── LoginActivity.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── madeel │ └── devicetracker │ └── ExampleUnitTest.java ├── build.gradle ├── css ├── bootstrap.css ├── bootstrap.min.css └── stylesheet.css ├── devicetracker.sql ├── fonts ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2 ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── js ├── bootstrap.js ├── bootstrap.min.js └── npm.js ├── mfekey.jks └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MF Enterprises -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vehicle-Tracking-System-WebApp-PHP 2 | This is a complete Vehicle Tracking System. It tracks a device real time and show its location on Map on Web App. It maintains the history of every device and user can view them history by date and time. The user will first register from android app then wait for approval from admin . Now admin from web app submitted requests and can view all the details, admin can approve the request or can delete it. After approval from admin the user will automatically will be redirected to login page and the tracking will begin. 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/MFE Vehicle Tracker.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/MFE Vehicle Tracker.apk -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/app-release.apk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | signingConfigs { 5 | config { 6 | keyAlias 'key1' 7 | keyPassword 'safety123' 8 | storePassword 'safety123' 9 | storeFile file('C:/Users/M.Adeel/Desktop/MF Enterprises (2)/MF Enterprises/mfekey.jks') 10 | } 11 | } 12 | compileSdkVersion 26 13 | buildToolsVersion '26.0.0' 14 | defaultConfig { 15 | applicationId "com.mfe.qurvex.devicetracker" 16 | minSdkVersion 21 17 | targetSdkVersion 26 18 | versionCode 1 19 | versionName "1.0" 20 | } 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | productFlavors { 28 | } 29 | } 30 | 31 | dependencies { 32 | compile fileTree(include: ['*.jar'], dir: 'libs') 33 | testCompile 'junit:junit:4.12' 34 | compile 'com.android.support:appcompat-v7:26.0.1' 35 | //compile 'com.android.support:appcompat-v7:27.0.1' 36 | compile files('libs/apache-httpcomponents-httpclient.jar') 37 | } 38 | -------------------------------------------------------------------------------- /app/libs/apache-httpcomponents-httpclient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/libs/apache-httpcomponents-httpclient.jar -------------------------------------------------------------------------------- /app/libs/apache-httpcomponents-httpcore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/libs/apache-httpcomponents-httpcore.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\M.Adeel\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/madeel/devicetracker/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/Approve.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | import android.net.Uri; 7 | import android.os.AsyncTask; 8 | import android.os.Handler; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.view.View; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import java.io.BufferedReader; 16 | import java.io.InputStream; 17 | import java.io.InputStreamReader; 18 | import java.net.HttpURLConnection; 19 | import java.net.MalformedURLException; 20 | import java.net.URL; 21 | import java.util.Timer; 22 | import java.util.TimerTask; 23 | 24 | public class Approve extends AppCompatActivity { 25 | TextView t ; 26 | private boolean approved=false; 27 | SharedPreferences sharedpreferences; 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_approve); 33 | t = (TextView)findViewById(R.id.textView6); 34 | sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 35 | t.setText(""+sharedpreferences.getString("username","")); 36 | repeatcheck(); 37 | 38 | } 39 | 40 | public void checkApproval(){ 41 | sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 42 | ///checkapp.php?key=1345&AUId=61 43 | Uri.Builder builder = new Uri.Builder(); 44 | builder.scheme("https") 45 | .authority("mfenter.com") 46 | 47 | .appendPath("tracker") 48 | .appendPath("checkapp.php") 49 | .appendQueryParameter("key", "1345") 50 | .appendQueryParameter("AUId", sharedpreferences.getString("AUId","")); 51 | 52 | 53 | String myUrl = builder.build().toString(); 54 | 55 | AsyncRetrieve as = new AsyncRetrieve(); 56 | as.u = myUrl; 57 | as.execute(); 58 | 59 | 60 | 61 | 62 | 63 | 64 | } 65 | Handler handler; 66 | public void repeatcheck(){ 67 | handler = new Handler(); 68 | final Timer timer = new Timer(); 69 | final TimerTask doAsynchronousTask = new TimerTask() { 70 | @Override 71 | public void run() { 72 | handler.post(new Runnable() { 73 | public void run() { 74 | try { 75 | checkApproval(); 76 | if(approved==true){ 77 | timer.cancel(); 78 | sharedpreferences.edit().putString("Approval","1").commit(); 79 | Toast.makeText(Approve.this, "Approved!", Toast.LENGTH_LONG).show(); 80 | Intent activityChangeIntent = new Intent(Approve.this, login.class); 81 | // currentContext.startActivity(activityChangeIntent); 82 | 83 | Approve.this.startActivity(activityChangeIntent); 84 | finishAffinity(); 85 | finish(); 86 | } 87 | 88 | } catch (Exception e) { 89 | // Toast.makeText(Approve.this, e.toString(), Toast.LENGTH_LONG).show(); 90 | } 91 | } 92 | }); 93 | } 94 | }; 95 | timer.schedule(doAsynchronousTask, 0, 100 ); //execute in every 50000 ms 96 | } 97 | 98 | public void logout1(View view){ 99 | Intent stopServiceIntent = new Intent(this, MyService.class); 100 | stopService(stopServiceIntent); 101 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 102 | SharedPreferences.Editor editor = sharedpreferences.edit(); 103 | editor.clear(); 104 | editor.commit(); 105 | Intent activityChangeIntent = new Intent(Approve.this,MainActivity.class); 106 | 107 | // currentContext.startActivity(activityChangeIntent); 108 | finishAffinity(); 109 | startActivity(activityChangeIntent); 110 | } 111 | 112 | 113 | public class AsyncRetrieve extends AsyncTask { 114 | HttpURLConnection conn; 115 | URL url = null; 116 | String u; 117 | String res; 118 | 119 | //this method will interact with UI, here display loading message 120 | @Override 121 | protected void onPreExecute() { 122 | super.onPreExecute(); 123 | 124 | 125 | } 126 | 127 | // This method does not interact with UI, You need to pass result to onPostExecute to display 128 | @Override 129 | protected String doInBackground(String... params) { 130 | try { 131 | // Enter URL address where your php file resides 132 | url = new URL(u); 133 | 134 | } catch (MalformedURLException e) { 135 | // TODO Auto-generated catch block 136 | e.printStackTrace(); 137 | return e.toString(); 138 | } 139 | try { 140 | 141 | // Setup HttpURLConnection class to send and receive data from php 142 | conn = (HttpURLConnection) url.openConnection(); 143 | 144 | conn.setRequestMethod("GET"); 145 | 146 | // setDoOutput to true as we recieve data from json file 147 | conn.setDoOutput(true); 148 | 149 | } catch (Exception e1) { 150 | // TODO Auto-generated catch block 151 | e1.printStackTrace(); 152 | cancel(true); 153 | //Toast.makeText(Approve.this, e1.toString(), Toast.LENGTH_LONG).show(); 154 | return e1.toString(); 155 | 156 | } 157 | 158 | try { 159 | 160 | int response_code = conn.getResponseCode(); 161 | 162 | // Check if successful connection made 163 | if (response_code == HttpURLConnection.HTTP_OK) { 164 | 165 | // Read data sent from server 166 | InputStream input = conn.getInputStream(); 167 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 168 | StringBuilder result = new StringBuilder(); 169 | String line; 170 | 171 | while ((line = reader.readLine()) != null) { 172 | result.append(line); 173 | } 174 | 175 | // Pass data to onPostExecute method 176 | return (result.toString()); 177 | 178 | } else { 179 | 180 | return ("unsuccessful"); 181 | } 182 | 183 | } catch (Exception e) { 184 | cancel(true); 185 | // Toast.makeText(register.this, e.toString(), Toast.LENGTH_LONG).show(); 186 | e.printStackTrace(); 187 | return e.toString(); 188 | } finally { 189 | conn.disconnect(); 190 | } 191 | 192 | 193 | } 194 | 195 | // this method will interact with UI, display result sent from doInBackground method 196 | @Override 197 | protected void onPostExecute(String result) { 198 | //Toast.makeText(Approve.this, result.trim(), Toast.LENGTH_LONG).show(); 199 | result.trim(); 200 | if(result.equals("1")){ 201 | 202 | approved =true; 203 | 204 | } 205 | 206 | 207 | 208 | 209 | } 210 | 211 | /*t2.setText(result.toString()); 212 | SharedPreferences.Editor editor = sharedpreferences.edit(); 213 | editor.putString("id" , result.toString()); 214 | sendgps(); 215 | /* res = result.toString(); 216 | result.trim(); 217 | if(res.equalsIgnoreCase("Succeed") ){ 218 | 219 | Toast.makeText(login.this, "Log In Succesfull!", Toast.LENGTH_LONG).show(); 220 | } 221 | else { 222 | Toast.makeText(login.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 223 | }*/ 224 | 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/GPSTracker.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | 4 | import android.Manifest; 5 | import android.app.Activity; 6 | import android.app.Service; 7 | import android.content.Context; 8 | import android.content.DialogInterface; 9 | import android.content.Intent; 10 | import android.content.pm.PackageManager; 11 | import android.location.Location; 12 | import android.location.LocationListener; 13 | import android.location.LocationManager; 14 | import android.os.Bundle; 15 | import android.os.IBinder; 16 | import android.provider.Settings; 17 | import android.support.v4.app.ActivityCompat; 18 | import android.support.v7.app.AlertDialog; 19 | import android.util.Log; 20 | 21 | class GPSTracker extends Service implements LocationListener { 22 | private final Context mContext; 23 | // flag for GPS status 24 | boolean isGPSEnabled = false; 25 | // flag for network status 26 | boolean isNetworkEnabled = false; 27 | // flag for GPS status 28 | boolean canGetLocation = false; 29 | Location location; // location 30 | double latitude; // latitude 31 | double longitude; // longitude 32 | // The minimum distance to change Updates in meters 33 | private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters 34 | // The minimum time between updates in milliseconds 35 | private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute 36 | // Declaring a Location Manager 37 | protected LocationManager locationManager; 38 | 39 | public GPSTracker(Context context) { 40 | this.mContext = context; 41 | getLocation(); 42 | } 43 | 44 | public Location getLocation() { 45 | try { 46 | locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); 47 | // getting GPS status 48 | isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 49 | // getting network status 50 | isNetworkEnabled = locationManager 51 | .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 52 | if (!isGPSEnabled && !isNetworkEnabled) { 53 | // no network provider is enabled 54 | } else { 55 | this.canGetLocation = true; 56 | // First get location from Network Provider 57 | if (isNetworkEnabled) { 58 | //check the network permission 59 | if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 60 | ActivityCompat.requestPermissions((Activity) mContext, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 101); 61 | } 62 | locationManager.requestLocationUpdates( 63 | LocationManager.NETWORK_PROVIDER, 64 | MIN_TIME_BW_UPDATES, 65 | MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 66 | Log.d("Network", "Network"); 67 | if (locationManager != null) { 68 | location = locationManager 69 | .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 70 | if (location != null) { 71 | latitude = location.getLatitude(); 72 | longitude = location.getLongitude(); 73 | } 74 | } 75 | } 76 | // if GPS Enabled get lat/long using GPS Services 77 | if (isGPSEnabled) { 78 | if (location == null) { 79 | //check the network permission 80 | if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 81 | ActivityCompat.requestPermissions((Activity) mContext, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 101); 82 | } 83 | locationManager.requestLocationUpdates( 84 | LocationManager.GPS_PROVIDER, 85 | MIN_TIME_BW_UPDATES, 86 | MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 87 | Log.d("GPS Enabled", "GPS Enabled"); 88 | if (locationManager != null) { 89 | location = locationManager 90 | .getLastKnownLocation(LocationManager.GPS_PROVIDER); 91 | if (location != null) { 92 | latitude = location.getLatitude(); 93 | longitude = location.getLongitude(); 94 | } 95 | } 96 | } 97 | } 98 | } 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | return 0; 103 | } 104 | 105 | /** 106 | * Stop using GPS listener 107 | * Calling this function will stop using GPS in your app 108 | * */ 109 | public void stopUsingGPS() { 110 | if (locationManager != null) { 111 | 112 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 113 | // TODO: Consider calling 114 | // ActivityCompat#requestPermissions 115 | // here to request the missing permissions, and then overriding 116 | // public void onRequestPermissionsResult(int requestCode, String[] permissions, 117 | // int[] grantResults) 118 | // to handle the case where the user grants the permission. See the documentation 119 | // for ActivityCompat#requestPermissions for more details. 120 | return; 121 | } 122 | locationManager.removeUpdates(GPSTracker.this); 123 | } 124 | } 125 | /** 126 | * Function to get latitude 127 | * */ 128 | public double getLatitude(){ 129 | if(location != null){ 130 | latitude = 0; 131 | } 132 | // return latitude 133 | return 0; 134 | } 135 | /** 136 | * Function to get longitude 137 | * */ 138 | public double getLongitude(){ 139 | if(location != null){ 140 | longitude = 0; 141 | } 142 | // return longitude 143 | return 0; 144 | } 145 | /** 146 | * Function to check GPS/wifi enabled 147 | * @return boolean 148 | * */ 149 | public boolean canGetLocation() { 150 | return this.canGetLocation; 151 | } 152 | /** 153 | * Function to show settings alert dialog 154 | * On pressing Settings button will lauch Settings Options 155 | * */ 156 | public void showSettingsAlert(){ 157 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext); 158 | // Setting Dialog Title 159 | alertDialog.setTitle("GPS is settings"); 160 | // Setting Dialog Message 161 | alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?"); 162 | // On pressing Settings button 163 | alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { 164 | public void onClick(DialogInterface dialog,int which) { 165 | Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 166 | mContext.startActivity(intent); 167 | } 168 | }); 169 | // on pressing cancel button 170 | alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 171 | public void onClick(DialogInterface dialog, int which) { 172 | dialog.cancel(); 173 | } 174 | }); 175 | alertDialog.show(); 176 | } 177 | @Override 178 | public void onLocationChanged(Location location) { 179 | } 180 | @Override 181 | public void onProviderDisabled(String provider) { 182 | } 183 | @Override 184 | public void onProviderEnabled(String provider) { 185 | } 186 | @Override 187 | public void onStatusChanged(String provider, int status, Bundle extras) { 188 | } 189 | @Override 190 | public IBinder onBind(Intent arg0) { 191 | return null; 192 | } 193 | } -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.net.Uri; 8 | import android.os.AsyncTask; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.view.View; 12 | import android.widget.EditText; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | import java.io.BufferedReader; 16 | import java.io.IOException; 17 | import java.io.InputStream; 18 | import java.io.InputStreamReader; 19 | import java.net.HttpURLConnection; 20 | import java.net.MalformedURLException; 21 | import java.net.URL; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | EditText username , password; 26 | // CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds 27 | public static final int CONNECTION_TIMEOUT = 10000; 28 | public static final int READ_TIMEOUT = 100; 29 | TextView textPHP; 30 | SharedPreferences sharedpreferences; 31 | public static final String mypreference = "mypref"; 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | sharedpreferences = getSharedPreferences(mypreference, 36 | Context.MODE_PRIVATE); 37 | 38 | setContentView(R.layout.activity_main); 39 | username = (EditText) findViewById(R.id.editText); 40 | password = (EditText) findViewById(R.id.editText2); 41 | 42 | 43 | 44 | 45 | } 46 | 47 | public void onregclick(View v){ 48 | Intent activityChangeIntent = new Intent(MainActivity.this,register.class); 49 | // currentContext.startActivity(activityChangeIntent); 50 | MainActivity.this.startActivity(activityChangeIntent); 51 | } 52 | //Make call to AsyncRetrieve 53 | public void onclickbtn(View v) { 54 | String user = username.getText().toString(); 55 | String pass = password.getText().toString(); 56 | if(user.isEmpty() || pass.isEmpty()){ 57 | 58 | Toast.makeText(MainActivity.this, 59 | "Fill all the fields!", Toast.LENGTH_LONG).show(); 60 | } 61 | else { 62 | 63 | //http://adeel20.000webhostapp.com/register.php?key=1234&username=kashif&password=1234&cdate=2018-9-3 64 | Uri.Builder builder = new Uri.Builder(); 65 | builder.scheme("https") 66 | .authority("mfenter.com") 67 | 68 | .appendPath("tracker") 69 | 70 | .appendPath("checklogin.php") 71 | .appendQueryParameter("key", "1345") 72 | .appendQueryParameter("username",user) 73 | .appendQueryParameter("password",pass); 74 | 75 | String myUrl = builder.build().toString(); 76 | AsyncRetrieve as = new AsyncRetrieve(); 77 | as.execute(); 78 | 79 | 80 | as.u = myUrl; 81 | 82 | 83 | 84 | } 85 | 86 | } 87 | 88 | 89 | private class AsyncRetrieve extends AsyncTask { 90 | ProgressDialog pdLoading = new ProgressDialog(MainActivity.this); 91 | HttpURLConnection conn; 92 | URL url = null; 93 | String u; 94 | String res; 95 | //this method will interact with UI, here display loading message 96 | @Override 97 | protected void onPreExecute() { 98 | super.onPreExecute(); 99 | 100 | pdLoading.setMessage("\tLogging In..."); 101 | pdLoading.setCancelable(false); 102 | pdLoading.show(); 103 | 104 | } 105 | 106 | // This method does not interact with UI, You need to pass result to onPostExecute to display 107 | @Override 108 | protected String doInBackground(String... params) { 109 | try { 110 | // Enter URL address where your php file resides 111 | url = new URL(u); 112 | 113 | } catch (MalformedURLException e) { 114 | // TODO Auto-generated catch block 115 | e.printStackTrace(); 116 | return e.toString(); 117 | } 118 | try { 119 | 120 | // Setup HttpURLConnection class to send and receive data from php 121 | conn = (HttpURLConnection) url.openConnection(); 122 | 123 | conn.setRequestMethod("GET"); 124 | 125 | // setDoOutput to true as we recieve data from json file 126 | conn.setDoOutput(true); 127 | 128 | } catch (IOException e1) { 129 | // TODO Auto-generated catch block 130 | e1.printStackTrace(); 131 | return e1.toString(); 132 | } 133 | 134 | try { 135 | 136 | int response_code = conn.getResponseCode(); 137 | 138 | // Check if successful connection made 139 | if (response_code == HttpURLConnection.HTTP_OK) { 140 | 141 | // Read data sent from server 142 | InputStream input = conn.getInputStream(); 143 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 144 | StringBuilder result = new StringBuilder(); 145 | String line; 146 | 147 | while ((line = reader.readLine()) != null) { 148 | result.append(line); 149 | } 150 | 151 | // Pass data to onPostExecute method 152 | return (result.toString()); 153 | 154 | } else { 155 | 156 | return ("unsuccessful"); 157 | } 158 | 159 | } catch (IOException e) { 160 | e.printStackTrace(); 161 | return e.toString(); 162 | } finally { 163 | conn.disconnect(); 164 | } 165 | 166 | 167 | } 168 | 169 | // this method will interact with UI, display result sent from doInBackground method 170 | @Override 171 | protected void onPostExecute(String result) { 172 | 173 | 174 | 175 | // you to understand error returned from doInBackground method 176 | result.trim(); 177 | 178 | res = result.toString(); 179 | String user = username.getText().toString(); 180 | 181 | 182 | if(res.equalsIgnoreCase("Succeed") ){ 183 | 184 | 185 | 186 | AsyncRetrieve1 as =new AsyncRetrieve1(); 187 | Uri.Builder builder = new Uri.Builder(); 188 | builder.scheme("https") 189 | .authority("mfenter.com") 190 | 191 | .appendPath("tracker") 192 | 193 | .appendPath("getauid.php") 194 | .appendQueryParameter("key", "1345") 195 | .appendQueryParameter("username",user); 196 | 197 | 198 | String myUrl = builder.build().toString(); 199 | 200 | as.execute(); 201 | 202 | 203 | as.u = myUrl; 204 | 205 | } 206 | else if(res.equalsIgnoreCase("na") ){ 207 | Toast.makeText(MainActivity.this, "User is no longer Active!", Toast.LENGTH_LONG).show(); 208 | } 209 | else { 210 | //Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_LONG).show(); 211 | Toast.makeText(MainActivity.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 212 | 213 | } 214 | pdLoading.dismiss(); 215 | 216 | } 217 | 218 | } 219 | 220 | 221 | 222 | 223 | 224 | 225 | private class AsyncRetrieve1 extends AsyncTask { 226 | ProgressDialog pdLoading = new ProgressDialog(MainActivity.this); 227 | HttpURLConnection conn; 228 | URL url = null; 229 | String u; 230 | String res; 231 | //this method will interact with UI, here display loading message 232 | @Override 233 | protected void onPreExecute() { 234 | super.onPreExecute(); 235 | 236 | pdLoading.setMessage("\tLogging In..."); 237 | pdLoading.setCancelable(false); 238 | pdLoading.show(); 239 | 240 | } 241 | 242 | // This method does not interact with UI, You need to pass result to onPostExecute to display 243 | @Override 244 | protected String doInBackground(String... params) { 245 | try { 246 | // Enter URL address where your php file resides 247 | url = new URL(u); 248 | 249 | } catch (MalformedURLException e) { 250 | // TODO Auto-generated catch block 251 | e.printStackTrace(); 252 | return e.toString(); 253 | } 254 | try { 255 | 256 | // Setup HttpURLConnection class to send and receive data from php 257 | conn = (HttpURLConnection) url.openConnection(); 258 | conn.setRequestMethod("GET"); 259 | 260 | // setDoOutput to true as we recieve data from json file 261 | conn.setDoOutput(true); 262 | 263 | } catch (IOException e1) { 264 | // TODO Auto-generated catch block 265 | e1.printStackTrace(); 266 | return e1.toString(); 267 | } 268 | 269 | try { 270 | 271 | int response_code = conn.getResponseCode(); 272 | 273 | // Check if successful connection made 274 | if (response_code == HttpURLConnection.HTTP_OK) { 275 | 276 | // Read data sent from server 277 | InputStream input = conn.getInputStream(); 278 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 279 | StringBuilder result = new StringBuilder(); 280 | String line; 281 | 282 | while ((line = reader.readLine()) != null) { 283 | result.append(line); 284 | } 285 | 286 | // Pass data to onPostExecute method 287 | return (result.toString()); 288 | 289 | } else { 290 | 291 | return ("unsuccessful"); 292 | } 293 | 294 | } catch (IOException e) { 295 | e.printStackTrace(); 296 | return e.toString(); 297 | } finally { 298 | conn.disconnect(); 299 | } 300 | 301 | 302 | } 303 | 304 | // this method will interact with UI, display result sent from doInBackground method 305 | @Override 306 | protected void onPostExecute(String result) { 307 | pdLoading.dismiss(); 308 | 309 | 310 | // you to understand error returned from doInBackground method 311 | result.trim(); 312 | 313 | res = result.toString(); 314 | SharedPreferences.Editor editor = sharedpreferences.edit(); 315 | editor.putString("AUId" , res); 316 | editor.commit(); 317 | Uri.Builder builder = new Uri.Builder(); 318 | builder.scheme("https") 319 | .authority("mfenter.com") 320 | 321 | .appendPath("tracker") 322 | .appendPath("checkapp.php") 323 | .appendQueryParameter("key", "1345") 324 | .appendQueryParameter("AUId", sharedpreferences.getString("AUId","")); 325 | 326 | 327 | String myUrl = builder.build().toString(); 328 | 329 | AsyncRetrieve2 as = new AsyncRetrieve2(); 330 | as.u = myUrl; 331 | as.execute(); 332 | 333 | 334 | 335 | } 336 | 337 | 338 | } 339 | 340 | 341 | 342 | 343 | private class AsyncRetrieve2 extends AsyncTask { 344 | ProgressDialog pdLoading = new ProgressDialog(MainActivity.this); 345 | HttpURLConnection conn; 346 | URL url = null; 347 | String u; 348 | String res; 349 | //this method will interact with UI, here display loading message 350 | @Override 351 | protected void onPreExecute() { 352 | super.onPreExecute(); 353 | 354 | pdLoading.setMessage("\tLogging In..."); 355 | pdLoading.setCancelable(false); 356 | pdLoading.show(); 357 | 358 | } 359 | 360 | // This method does not interact with UI, You need to pass result to onPostExecute to display 361 | @Override 362 | protected String doInBackground(String... params) { 363 | try { 364 | // Enter URL address where your php file resides 365 | url = new URL(u); 366 | 367 | } catch (MalformedURLException e) { 368 | // TODO Auto-generated catch block 369 | e.printStackTrace(); 370 | return e.toString(); 371 | } 372 | try { 373 | 374 | // Setup HttpURLConnection class to send and receive data from php 375 | conn = (HttpURLConnection) url.openConnection(); 376 | conn.setRequestMethod("GET"); 377 | 378 | // setDoOutput to true as we recieve data from json file 379 | conn.setDoOutput(true); 380 | 381 | } catch (IOException e1) { 382 | // TODO Auto-generated catch block 383 | e1.printStackTrace(); 384 | return e1.toString(); 385 | } 386 | 387 | try { 388 | 389 | int response_code = conn.getResponseCode(); 390 | 391 | // Check if successful connection made 392 | if (response_code == HttpURLConnection.HTTP_OK) { 393 | 394 | // Read data sent from server 395 | InputStream input = conn.getInputStream(); 396 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 397 | StringBuilder result = new StringBuilder(); 398 | String line; 399 | 400 | while ((line = reader.readLine()) != null) { 401 | result.append(line); 402 | } 403 | 404 | // Pass data to onPostExecute method 405 | return (result.toString()); 406 | 407 | } else { 408 | 409 | return ("unsuccessful"); 410 | } 411 | 412 | } catch (IOException e) { 413 | e.printStackTrace(); 414 | return e.toString(); 415 | } finally { 416 | conn.disconnect(); 417 | } 418 | 419 | 420 | } 421 | 422 | // this method will interact with UI, display result sent from doInBackground method 423 | @Override 424 | protected void onPostExecute(String result) { 425 | pdLoading.dismiss(); 426 | result.trim(); 427 | String user = username.getText().toString(); 428 | String pass = password.getText().toString(); 429 | if(result.equals("1")){ 430 | sharedpreferences.edit().putString("Approval","1").commit(); 431 | SharedPreferences.Editor editor = sharedpreferences.edit(); 432 | editor.putString("username" , user); 433 | editor.putString("password", pass); 434 | editor.commit(); 435 | Intent activityChangeIntent = new Intent(MainActivity.this, login.class); 436 | // currentContext.startActivity(activityChangeIntent); 437 | finishAffinity(); 438 | 439 | startActivity(activityChangeIntent); 440 | 441 | } 442 | else{ 443 | sharedpreferences.edit().putString("Approval","0").commit(); 444 | SharedPreferences.Editor editor = sharedpreferences.edit(); 445 | editor.putString("username" , user); 446 | editor.putString("password", pass); 447 | editor.commit(); 448 | Intent activityChangeIntent = new Intent(MainActivity.this, Approve.class); 449 | // currentContext.startActivity(activityChangeIntent); 450 | finishAffinity(); 451 | 452 | startActivity(activityChangeIntent); 453 | } 454 | 455 | 456 | 457 | 458 | } 459 | 460 | }} 461 | 462 | -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/MyService.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Notification; 5 | import android.app.NotificationManager; 6 | import android.app.PendingIntent; 7 | import android.app.Service; 8 | import android.content.Context; 9 | import android.content.DialogInterface; 10 | import android.content.Intent; 11 | import android.content.pm.PackageManager; 12 | import android.graphics.Color; 13 | import android.location.LocationManager; 14 | import android.net.Uri; 15 | import android.os.AsyncTask; 16 | import android.os.Handler; 17 | import android.os.IBinder; 18 | import android.provider.Settings; 19 | import android.support.v4.app.ActivityCompat; 20 | import android.support.v4.app.NotificationCompat; 21 | import android.support.v4.content.ContextCompat; 22 | import android.widget.Toast; 23 | 24 | import java.io.BufferedReader; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.InputStreamReader; 28 | import java.net.HttpURLConnection; 29 | import java.net.MalformedURLException; 30 | import java.net.URL; 31 | import java.text.SimpleDateFormat; 32 | import java.util.Calendar; 33 | import java.util.Date; 34 | import java.util.Random; 35 | import java.util.Timer; 36 | import java.util.TimerTask; 37 | 38 | /** 39 | * Created by Belal on 12/30/2016. 40 | */ 41 | 42 | public class MyService extends Service { 43 | //SharedPreferences sharedpreferences ; 44 | String s; 45 | Timer timer1; 46 | public MyService() { 47 | 48 | // sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 49 | } 50 | void getid(String s){ 51 | this.s=s; 52 | 53 | } 54 | 55 | 56 | private void showNotification( ) { 57 | Intent notificationIntent = new Intent(this, MainActivity.class); 58 | notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 59 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 60 | notificationIntent, 0); 61 | int iconId = R.drawable.logo; 62 | int uniqueCode = new Random().nextInt(Integer.MAX_VALUE); 63 | Notification notification = new NotificationCompat.Builder(this) 64 | .setSmallIcon(iconId) 65 | .setContentTitle("MFE Vehicle Tracker") 66 | .setContentText("Tracking Location of your device...") 67 | .setContentIntent(pendingIntent).build(); 68 | startForeground(uniqueCode, notification); 69 | 70 | 71 | 72 | } 73 | public void callAsynchronousTask() { 74 | final Handler handler = new Handler(); 75 | Timer timer = new Timer(); 76 | TimerTask doAsynchronousTask = new TimerTask() { 77 | @Override 78 | public void run() { 79 | handler.post(new Runnable() { 80 | public void run() { 81 | try { 82 | sendgps(); 83 | // Toast.makeText(null,"sdfsdf", Toast.LENGTH_LONG).show(); 84 | } catch (Exception e) { 85 | 86 | } 87 | } 88 | }); 89 | } 90 | }; 91 | timer.schedule(doAsynchronousTask, 0, 15000); 92 | 93 | } 94 | public void sendgps() { 95 | 96 | Date c = Calendar.getInstance().getTime(); 97 | //System.out.println("Current time => " + c); 98 | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 99 | String formattedDate = fmt.format(c); 100 | 101 | 102 | //Toast.makeText(login.this, formattedDate, Toast.LENGTH_LONG).show(); 103 | //String s = 104 | AsyncRetrieve2 sa = new AsyncRetrieve2(); 105 | Uri.Builder builder1 = new Uri.Builder(); 106 | GPSTracker gps = new GPSTracker(this); 107 | double latitude = gps.getLatitude(); 108 | double longitude = gps.getLongitude(); 109 | //getgps.php/?key=1345&lat=45&lon=55&AUId=2&lup=2018-09-04%2002:04:20 110 | if(latitude > 22 || longitude>22) { 111 | builder1.scheme("https") 112 | .authority("mfenter.com") 113 | 114 | .appendPath("tracker") 115 | 116 | .appendPath("getgps.php") 117 | .appendQueryParameter("key", "1345") 118 | .appendQueryParameter("AUId", login.sharedpreferences.getString("AUId", "")) 119 | .appendQueryParameter("lat", String.valueOf(latitude)) 120 | .appendQueryParameter("lon", String.valueOf(longitude)) 121 | .appendQueryParameter("lup", formattedDate); 122 | String myUrl1 = builder1.build().toString(); 123 | sa.u = myUrl1; 124 | sa.execute(); 125 | } 126 | 127 | // Toast.makeText(login.this, String.valueOf(latitude), Toast.LENGTH_LONG).show(); 128 | 129 | } 130 | public void callAsynchronousTask1() { 131 | final Handler handler = new Handler(); 132 | timer1 = new Timer(); 133 | TimerTask doAsynchronousTask = new TimerTask() { 134 | @Override 135 | public void run() { 136 | handler.post(new Runnable() { 137 | public void run() { 138 | try { 139 | checkGPSStatus(); 140 | } catch (Exception e) { 141 | // Toast.makeText(login.this, e.toString(), Toast.LENGTH_LONG).show(); 142 | } 143 | } 144 | }); 145 | } 146 | }; 147 | timer1.schedule(doAsynchronousTask, 0, 5000); //execute in every 50000 ms 148 | } 149 | static int ncheck=0; 150 | private void checkGPSStatus() { 151 | LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); 152 | boolean gps_enabled = false; 153 | boolean network_enabled = false; 154 | 155 | try { 156 | gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); 157 | } catch(Exception ex) {} 158 | 159 | try { 160 | network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 161 | } catch(Exception ex) {} 162 | Intent notificationIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); 163 | 164 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 165 | notificationIntent, 0); 166 | int iconId = R.drawable.logo; 167 | int uniqueCode = new Random().nextInt(Integer.MAX_VALUE); 168 | Notification notification = new NotificationCompat.Builder(this) 169 | 170 | .setSmallIcon(iconId) 171 | .setContentTitle("MFE Vehicle Tracker") 172 | .setContentText("Location is not Enabled.. Click to go to Settings!") 173 | .setOngoing(true) 174 | .setVibrate(new long[]{1000,1000,1000,1000,1000}) 175 | .setLights(Color.RED,3000,3000) 176 | .setContentIntent(pendingIntent).build(); 177 | 178 | NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 179 | 180 | if(!gps_enabled && !network_enabled) { 181 | // notify user 182 | 183 | if(ncheck==0) { 184 | nm.notify(1, notification); 185 | ncheck = 1; 186 | } 187 | 188 | 189 | 190 | 191 | // testdialog.show(); 192 | 193 | } 194 | else{ 195 | nm.cancel(1); 196 | ncheck=0; 197 | //testdialog.dismiss(); 198 | } 199 | } 200 | public void sendgpstohistory() { 201 | 202 | Date c = Calendar.getInstance().getTime(); 203 | //System.out.println("Current time => " + c); 204 | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); 205 | String formattedDate = fmt.format(c); 206 | 207 | fmt = new SimpleDateFormat("HH:mm:ss"); 208 | String formattedtm = fmt.format(c); 209 | 210 | 211 | //Toast.makeText(login.this, formattedDate, Toast.LENGTH_LONG).show(); 212 | //String s = 213 | AsyncRetrieve2 sa = new AsyncRetrieve2(); 214 | Uri.Builder builder1 = new Uri.Builder(); 215 | GPSTracker gps = new GPSTracker(this); 216 | double latitude = gps.getLatitude(); 217 | double longitude = gps.getLongitude(); 218 | if(latitude >22 || longitude>22) { 219 | //inserthistory.php/?key=1345&lat=45&lon=55&username=ayesha222&dt=2018-09-04&tm=02:04:20 220 | builder1.scheme("https") 221 | .authority("mfenter.com") 222 | 223 | .appendPath("tracker") 224 | .appendPath("inserthistory.php") 225 | .appendQueryParameter("key", "1345") 226 | .appendQueryParameter("username", login.sharedpreferences.getString("username", "")) 227 | .appendQueryParameter("lat", String.valueOf(latitude)) 228 | .appendQueryParameter("lon", String.valueOf(longitude)) 229 | .appendQueryParameter("dt", formattedDate) 230 | .appendQueryParameter("tm", formattedtm); 231 | String myUrl1 = builder1.build().toString(); 232 | sa.u = myUrl1; 233 | sa.execute(); 234 | } 235 | else { 236 | 237 | // Toast.makeText(MyService.this, "Please Enable the Location Service!", Toast.LENGTH_LONG).show(); 238 | } 239 | // Toast.makeText(login.this, String.valueOf(latitude), Toast.LENGTH_LONG).show(); 240 | 241 | } 242 | 243 | @Override 244 | public IBinder onBind(Intent intent) { 245 | // TODO: Return the communication channel to the service. 246 | //Log.w("MyService", "onBind callback called"); 247 | throw new UnsupportedOperationException("Not yet implemented"); 248 | } 249 | 250 | @Override 251 | public int onStartCommand(Intent intent, int flags, int startId) { 252 | // Log.w("MyService", "onStartCommand callback called"); 253 | callAsynchronousTask1(); 254 | callAsynchronousTask(); 255 | showNotification(); 256 | return super.onStartCommand(intent, flags, startId); 257 | 258 | 259 | } 260 | 261 | @Override 262 | public void onCreate() { 263 | super.onCreate(); 264 | // Log.w("MyService", "onCreate callback called"); 265 | } 266 | 267 | @Override 268 | public void onDestroy() { 269 | ncheck=0; 270 | timer1.cancel(); 271 | 272 | super.onDestroy(); 273 | // Log.w("MyService", "onDestroy callback called"); 274 | } 275 | 276 | public class AsyncRetrieve2 extends AsyncTask { 277 | 278 | HttpURLConnection conn; 279 | URL url = null; 280 | String u; 281 | String res; 282 | 283 | //this method will interact with UI, here display loading message 284 | @Override 285 | protected void onPreExecute() { 286 | super.onPreExecute(); 287 | 288 | /* pdLoading.setMessage("\tLoading..."); 289 | pdLoading.setCancelable(false); 290 | pdLoading.show();*/ 291 | 292 | } 293 | 294 | // This method does not interact with UI, You need to pass result to onPostExecute to display 295 | @Override 296 | protected String doInBackground(String... params) { 297 | try { 298 | // Enter URL address where your php file resides 299 | url = new URL(u); 300 | 301 | } catch (MalformedURLException e) { 302 | // TODO Auto-generated catch block 303 | e.printStackTrace(); 304 | return e.toString(); 305 | } 306 | try { 307 | 308 | // Setup HttpURLConnection class to send and receive data from php 309 | conn = (HttpURLConnection) url.openConnection(); 310 | conn.setRequestMethod("GET"); 311 | 312 | // setDoOutput to true as we recieve data from json file 313 | conn.setDoOutput(true); 314 | 315 | } catch (IOException e1) { 316 | // TODO Auto-generated catch block 317 | e1.printStackTrace(); 318 | return e1.toString(); 319 | } 320 | 321 | try { 322 | 323 | int response_code = conn.getResponseCode(); 324 | 325 | // Check if successful connection made 326 | if (response_code == HttpURLConnection.HTTP_OK) { 327 | 328 | // Read data sent from server 329 | InputStream input = conn.getInputStream(); 330 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 331 | StringBuilder result = new StringBuilder(); 332 | String line; 333 | 334 | while ((line = reader.readLine()) != null) { 335 | result.append(line); 336 | } 337 | 338 | // Pass data to onPostExecute method 339 | return (result.toString()); 340 | 341 | } else { 342 | 343 | return ("unsuccessful"); 344 | } 345 | 346 | } catch (IOException e) { 347 | e.printStackTrace(); 348 | return e.toString(); 349 | } finally { 350 | conn.disconnect(); 351 | } 352 | 353 | 354 | } 355 | 356 | // this method will interact with UI, display result sent from doInBackground method 357 | @Override 358 | protected void onPostExecute(String result) { 359 | 360 | //pdLoading.dismiss(); 361 | 362 | // you to understand error returned from doInBackground method 363 | /* res = result.toString(); 364 | result.trim(); 365 | if(res.equalsIgnoreCase("Succeed") ){ 366 | 367 | Toast.makeText(login.this, "Log In Succesfull!", Toast.LENGTH_LONG).show(); 368 | } 369 | else { 370 | Toast.makeText(login.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 371 | }*/ 372 | 373 | } 374 | 375 | } 376 | } 377 | 378 | -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/SplashScreen.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.content.Intent; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | 8 | public class SplashScreen extends AppCompatActivity { 9 | 10 | 11 | private static int SPLASH_TIME_OUT = 2000; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | //this.requestWindowFeature(Window.FEATURE_NO_TITLE); 17 | //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 18 | setContentView(R.layout.activity_splash_screen); 19 | 20 | new Handler().postDelayed(new Runnable() { 21 | 22 | /* 23 | * Showing splash screen with a timer. This will be useful when you 24 | * want to show case your app logo / company 25 | */ 26 | 27 | @Override 28 | public void run() { 29 | // This method will be executed once the timer is over 30 | // Start your app main activity 31 | Intent i = new Intent(SplashScreen.this, MainActivity.class); 32 | startActivity(i); 33 | 34 | // close this activity 35 | finish(); 36 | } 37 | }, SPLASH_TIME_OUT); 38 | }} -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/login.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | 3 | import android.app.ActivityManager; 4 | import android.app.AlertDialog; 5 | import android.app.NotificationManager; 6 | import android.app.ProgressDialog; 7 | import android.content.Context; 8 | import android.content.DialogInterface; 9 | import android.content.Intent; 10 | import android.content.SharedPreferences; 11 | import android.content.pm.PackageManager; 12 | import android.location.LocationManager; 13 | import android.net.Uri; 14 | import android.os.AsyncTask; 15 | import android.os.Handler; 16 | import android.provider.Settings; 17 | import android.support.v4.app.ActivityCompat; 18 | import android.support.v4.content.ContextCompat; 19 | import android.support.v7.app.AppCompatActivity; 20 | import android.os.Bundle; 21 | import android.view.View; 22 | import android.widget.TextView; 23 | import android.widget.Toast; 24 | 25 | import org.json.JSONException; 26 | import org.json.JSONObject; 27 | 28 | import java.io.BufferedReader; 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | import java.io.InputStreamReader; 32 | import java.net.HttpURLConnection; 33 | import java.net.MalformedURLException; 34 | import java.net.URL; 35 | import java.text.SimpleDateFormat; 36 | import java.util.Calendar; 37 | import java.util.Date; 38 | import java.util.Timer; 39 | import java.util.TimerTask; 40 | 41 | public class login extends AppCompatActivity { 42 | public static int approval=1; 43 | private GPSTracker gpsTracker; 44 | TextView t,fname,lname,address,cellno,vehicleno,brokerno,cnic,partyname; 45 | static SharedPreferences sharedpreferences ; 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.activity_login); 50 | fname = (TextView)findViewById(R.id.txtfname); 51 | lname = (TextView)findViewById(R.id.txtlname); 52 | address = (TextView)findViewById(R.id.txtAddress); 53 | cellno = (TextView)findViewById(R.id.txtCEllno); 54 | vehicleno = (TextView)findViewById(R.id.txtVehicleno); 55 | brokerno = (TextView)findViewById(R.id.txtBrokername); 56 | cnic = (TextView)findViewById(R.id.txtcnic); 57 | partyname = (TextView)findViewById(R.id.txtpartyname); 58 | sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 59 | //Toast.makeText(login.this, sharedpreferences.getString("Approval",""), Toast.LENGTH_LONG).show(); 60 | 61 | 62 | if(sharedpreferences.getString("Approval","").equals("0")){ 63 | Intent activityChangeIntent = new Intent(login.this, Approve.class); 64 | 65 | // currentContext.startActivity(activityChangeIntent); 66 | finishAffinity(); 67 | 68 | login.this.startActivity(activityChangeIntent); 69 | 70 | 71 | } 72 | else { 73 | try { 74 | 75 | if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 76 | ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 101); 77 | } 78 | else { 79 | if (!isMyServiceRunning(MyService.class)) { 80 | Intent myServiceIntent = new Intent(this, MyService.class); 81 | startService(myServiceIntent); 82 | } 83 | } 84 | 85 | 86 | } catch (Exception e) { 87 | e.printStackTrace(); 88 | } 89 | 90 | sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 91 | t = (TextView) findViewById(R.id.username); 92 | t.setText( " Username: "+ sharedpreferences.getString("username", "")); 93 | 94 | 95 | final Handler handler = new Handler(); 96 | final Timer timer = new Timer(); 97 | final TimerTask doAsynchronousTask = new TimerTask() { 98 | @Override 99 | public void run() { 100 | handler.post(new Runnable() { 101 | public void run() { 102 | try { 103 | AsyncRetrieve3 as = new AsyncRetrieve3(); 104 | //"loaddetails.php?key=1234&AUId=52"; 105 | String Auiid = sharedpreferences.getString("AUId", ""); 106 | 107 | Uri.Builder builder1 = new Uri.Builder(); 108 | 109 | builder1.scheme("https") 110 | .authority("mfenter.com") 111 | 112 | .appendPath("tracker") 113 | 114 | .appendPath("loaddetails.php") 115 | .appendQueryParameter("key","1234") 116 | .appendQueryParameter("AUId", Auiid); 117 | 118 | String myUrl1 = builder1.build().toString(); 119 | as.u = myUrl1; 120 | 121 | as.execute(); 122 | } catch (Exception e) { 123 | // Toast.makeText(Approve.this, e.toString(), Toast.LENGTH_LONG).show(); 124 | } 125 | } 126 | }); 127 | } 128 | }; 129 | timer.schedule(doAsynchronousTask, 0, 30000 ); 130 | //loaddetails.php?key=1234&AUId=52 131 | 132 | 133 | 134 | //GPSTracker g = new GPSTracker(this); 135 | //Toast.makeText(login.this, sharedpreferences.getString("Approval","").equals("0"), Toast.LENGTH_LONG).show(); 136 | 137 | 138 | } 139 | 140 | //callAsynchronousTask(); 141 | } 142 | @Override 143 | public void onRequestPermissionsResult(int requestCode, 144 | String permissions[], int[] grantResults) { 145 | switch (requestCode) { 146 | case 101: { 147 | 148 | // If request is cancelled, the result arrays are empty. 149 | if (grantResults.length > 0 150 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 151 | if (!isMyServiceRunning(MyService.class)) { 152 | Intent myServiceIntent = new Intent(this, MyService.class); 153 | startService(myServiceIntent); 154 | } 155 | 156 | // permission was granted, yay! Do the 157 | // contacts-related task you need to do. 158 | } else { 159 | // Toast.makeText(login.this, "Permission denied!", Toast.LENGTH_SHORT).show(); 160 | //finish(); 161 | if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 162 | ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 101); 163 | } 164 | // permission denied, boo! Disable the 165 | // functionality that depends on this permission. 166 | 167 | } 168 | return; 169 | } 170 | 171 | // other 'case' lines to check for other 172 | // permissions this app might request 173 | } 174 | } 175 | private boolean isMyServiceRunning(Class serviceClass) { 176 | ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 177 | for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 178 | if (serviceClass.getName().equals(service.service.getClassName())) { 179 | return true; 180 | } 181 | } 182 | return false; 183 | } 184 | private void checkGPSStatus() { 185 | LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); 186 | boolean gps_enabled = false; 187 | boolean network_enabled = false; 188 | 189 | try { 190 | gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); 191 | } catch(Exception ex) {} 192 | 193 | try { 194 | network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 195 | } catch(Exception ex) {} 196 | AlertDialog.Builder dialog = new AlertDialog.Builder(this); 197 | dialog.setMessage("Location Service is not enabled! Please Enable it."); 198 | dialog.setPositiveButton("Go To Settings", new DialogInterface.OnClickListener() { 199 | @Override 200 | public void onClick(DialogInterface paramDialogInterface, int paramInt) { 201 | // TODO Auto-generated method stub 202 | Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); 203 | startActivity(myIntent); 204 | //get gps 205 | } 206 | }); 207 | dialog.setCancelable(true); 208 | AlertDialog testdialog = dialog.create(); 209 | if(!gps_enabled && !network_enabled) { 210 | // notify user 211 | 212 | 213 | 214 | testdialog.show(); 215 | 216 | } 217 | else{ 218 | testdialog.dismiss(); 219 | } 220 | } 221 | public void callAsynchronousTask() { 222 | final Handler handler = new Handler(); 223 | Timer timer = new Timer(); 224 | TimerTask doAsynchronousTask = new TimerTask() { 225 | @Override 226 | public void run() { 227 | handler.post(new Runnable() { 228 | public void run() { 229 | try { 230 | checkGPSStatus(); 231 | } catch (Exception e) { 232 | // Toast.makeText(login.this, e.toString(), Toast.LENGTH_LONG).show(); 233 | } 234 | } 235 | }); 236 | } 237 | }; 238 | timer.schedule(doAsynchronousTask, 0, 6000); //execute in every 50000 ms 239 | } 240 | public void sendgps() { 241 | 242 | Date c = Calendar.getInstance().getTime(); 243 | //System.out.println("Current time => " + c); 244 | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 245 | String formattedDate = fmt.format(c); 246 | 247 | 248 | //Toast.makeText(login.this, formattedDate, Toast.LENGTH_LONG).show(); 249 | String s = sharedpreferences.getString("AUId", ""); 250 | AsyncRetrieve2 sa = new AsyncRetrieve2(); 251 | Uri.Builder builder1 = new Uri.Builder(); 252 | GPSTracker gps = new GPSTracker(this); 253 | double latitude = gps.getLatitude(); 254 | double longitude = gps.getLongitude(); 255 | //getgps.php/?key=1345&lat=45&lon=55&AUId=2&lup=2018-09-04%2002:04:20 256 | builder1.scheme("https") 257 | .authority("mfenter.com") 258 | 259 | .appendPath("tracker") 260 | 261 | .appendPath("getgps.php") 262 | .appendQueryParameter("key","1345") 263 | .appendQueryParameter("AUId", s) 264 | .appendQueryParameter("lat", String.valueOf(latitude)) 265 | .appendQueryParameter("lon",String.valueOf(longitude)) 266 | .appendQueryParameter("lup", formattedDate ); 267 | String myUrl1 = builder1.build().toString(); 268 | sa.u = myUrl1; 269 | sa.execute(); 270 | // Toast.makeText(login.this, String.valueOf(latitude), Toast.LENGTH_LONG).show(); 271 | 272 | } 273 | public void logout(View view){ 274 | Intent stopServiceIntent = new Intent(this, MyService.class); 275 | stopService(stopServiceIntent); 276 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 277 | SharedPreferences.Editor editor = sharedpreferences.edit(); 278 | editor.clear(); 279 | editor.commit(); 280 | Intent activityChangeIntent = new Intent(login.this,MainActivity.class); 281 | 282 | // currentContext.startActivity(activityChangeIntent); 283 | finishAffinity(); 284 | NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 285 | nm.cancel(1); 286 | login.this.startActivity(activityChangeIntent); 287 | } 288 | public class AsyncRetrieve2 extends AsyncTask { 289 | ProgressDialog pdLoading = new ProgressDialog(login.this); 290 | HttpURLConnection conn; 291 | URL url = null; 292 | String u; 293 | String res; 294 | 295 | //this method will interact with UI, here display loading message 296 | @Override 297 | protected void onPreExecute() { 298 | super.onPreExecute(); 299 | 300 | /* pdLoading.setMessage("\tLoading..."); 301 | pdLoading.setCancelable(false); 302 | pdLoading.show();*/ 303 | 304 | } 305 | 306 | // This method does not interact with UI, You need to pass result to onPostExecute to display 307 | @Override 308 | protected String doInBackground(String... params) { 309 | try { 310 | // Enter URL address where your php file resides 311 | url = new URL(u); 312 | 313 | } catch (MalformedURLException e) { 314 | // TODO Auto-generated catch block 315 | e.printStackTrace(); 316 | return e.toString(); 317 | } 318 | try { 319 | 320 | // Setup HttpURLConnection class to send and receive data from php 321 | conn = (HttpURLConnection) url.openConnection(); 322 | conn.setRequestMethod("GET"); 323 | 324 | // setDoOutput to true as we recieve data from json file 325 | conn.setDoOutput(true); 326 | 327 | } catch (IOException e1) { 328 | // TODO Auto-generated catch block 329 | e1.printStackTrace(); 330 | return e1.toString(); 331 | } 332 | 333 | try { 334 | 335 | int response_code = conn.getResponseCode(); 336 | 337 | // Check if successful connection made 338 | if (response_code == HttpURLConnection.HTTP_OK) { 339 | 340 | // Read data sent from server 341 | InputStream input = conn.getInputStream(); 342 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 343 | StringBuilder result = new StringBuilder(); 344 | String line; 345 | 346 | while ((line = reader.readLine()) != null) { 347 | result.append(line); 348 | } 349 | 350 | // Pass data to onPostExecute method 351 | return (result.toString()); 352 | 353 | } else { 354 | 355 | return ("unsuccessful"); 356 | } 357 | 358 | } catch (IOException e) { 359 | e.printStackTrace(); 360 | return e.toString(); 361 | } finally { 362 | conn.disconnect(); 363 | } 364 | 365 | 366 | } 367 | 368 | // this method will interact with UI, display result sent from doInBackground method 369 | @Override 370 | protected void onPostExecute(String result) { 371 | 372 | //pdLoading.dismiss(); 373 | 374 | // you to understand error returned from doInBackground method 375 | /* res = result.toString(); 376 | result.trim(); 377 | if(res.equalsIgnoreCase("Succeed") ){ 378 | 379 | Toast.makeText(login.this, "Log In Succesfull!", Toast.LENGTH_LONG).show(); 380 | } 381 | else { 382 | Toast.makeText(login.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 383 | }*/ 384 | 385 | } 386 | 387 | } 388 | public class AsyncRetrieve3 extends AsyncTask { 389 | 390 | HttpURLConnection conn; 391 | URL url = null; 392 | String u; 393 | String res; 394 | 395 | //this method will interact with UI, here display loading message 396 | @Override 397 | protected void onPreExecute() { 398 | super.onPreExecute(); 399 | 400 | /* pdLoading.setMessage("\tLoading..."); 401 | pdLoading.setCancelable(false); 402 | pdLoading.show();*/ 403 | 404 | } 405 | 406 | // This method does not interact with UI, You need to pass result to onPostExecute to display 407 | @Override 408 | protected String doInBackground(String... params) { 409 | try { 410 | // Enter URL address where your php file resides 411 | url = new URL(u); 412 | 413 | } catch (MalformedURLException e) { 414 | // TODO Auto-generated catch block 415 | e.printStackTrace(); 416 | return e.toString(); 417 | } 418 | try { 419 | 420 | // Setup HttpURLConnection class to send and receive data from php 421 | conn = (HttpURLConnection) url.openConnection(); 422 | conn.setRequestMethod("GET"); 423 | 424 | // setDoOutput to true as we recieve data from json file 425 | conn.setDoOutput(true); 426 | 427 | } catch (IOException e1) { 428 | // TODO Auto-generated catch block 429 | e1.printStackTrace(); 430 | return e1.toString(); 431 | } 432 | 433 | try { 434 | 435 | int response_code = conn.getResponseCode(); 436 | 437 | // Check if successful connection made 438 | if (response_code == HttpURLConnection.HTTP_OK) { 439 | 440 | // Read data sent from server 441 | InputStream input = conn.getInputStream(); 442 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 443 | StringBuilder result = new StringBuilder(); 444 | String line; 445 | 446 | while ((line = reader.readLine()) != null) { 447 | result.append(line); 448 | } 449 | 450 | // Pass data to onPostExecute method 451 | return (result.toString()); 452 | 453 | } else { 454 | 455 | return ("unsuccessful"); 456 | } 457 | 458 | } catch (IOException e) { 459 | e.printStackTrace(); 460 | return e.toString(); 461 | } finally { 462 | conn.disconnect(); 463 | } 464 | 465 | 466 | } 467 | 468 | // this method will interact with UI, display result sent from doInBackground method 469 | @Override 470 | protected void onPostExecute(String result) { 471 | 472 | //pdLoading.dismiss(); 473 | 474 | // you to understand error returned from doInBackground method 475 | /* res = result.toString(); 476 | result.trim(); 477 | if(res.equalsIgnoreCase("Succeed") ){ 478 | 479 | Toast.makeText(login.this, "Log In Succesfull!", Toast.LENGTH_LONG).show(); 480 | } 481 | else { 482 | Toast.makeText(login.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 483 | }*/ 484 | try { 485 | JSONObject obj = new JSONObject(result); 486 | fname.setText("First Name: "+obj.get("firstname").toString()); 487 | lname.setText("Last Name: "+obj.get("lastname").toString()); 488 | address.setText("Address: "+obj.get("address").toString()); 489 | cellno.setText("Cell No: "+obj.get("cellno").toString()); 490 | vehicleno.setText("Vehicle No: "+obj.get("vehicleno").toString()); 491 | brokerno.setText("Broker No: "+ obj.get("brokerno").toString()); 492 | cnic.setText("CNIC No: "+ obj.get("cnic").toString()); 493 | partyname.setText("Party Name: "+ obj.get("partyname").toString()); 494 | 495 | if(obj.get("status").toString().trim().equals("0")){ 496 | Toast.makeText(login.this, "User no longer active!", Toast.LENGTH_LONG).show(); 497 | Intent stopServiceIntent = new Intent(login.this, MyService.class); 498 | stopService(stopServiceIntent); 499 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 500 | SharedPreferences.Editor editor = sharedpreferences.edit(); 501 | editor.clear(); 502 | editor.commit(); 503 | Intent activityChangeIntent = new Intent(login.this,MainActivity.class); 504 | 505 | // currentContext.startActivity(activityChangeIntent); 506 | finishAffinity(); 507 | NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 508 | nm.cancel(1); 509 | login.this.startActivity(activityChangeIntent); 510 | } 511 | } catch (JSONException e) { 512 | e.printStackTrace(); 513 | } 514 | 515 | } 516 | 517 | } 518 | @Override 519 | public void onBackPressed() { 520 | moveTaskToBack(true); 521 | }} 522 | 523 | -------------------------------------------------------------------------------- /app/src/main/java/com/mfe/madeel/devicetracker/register.java: -------------------------------------------------------------------------------- 1 | package com.mfe.madeel.devicetracker; 2 | import android.app.ProgressDialog; 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | 7 | import android.net.Uri; 8 | import android.os.AsyncTask; 9 | 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.os.Bundle; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.EditText; 15 | import android.widget.Toast; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.InputStreamReader; 21 | import java.net.HttpURLConnection; 22 | import java.net.MalformedURLException; 23 | import java.net.URL; 24 | import java.text.SimpleDateFormat; 25 | import java.util.Calendar; 26 | import java.util.Date; 27 | 28 | public class register extends AppCompatActivity { 29 | EditText username,password,rpassword,firstname,lastname,address,cellno,brokerno,cnic,vehicleno,partyname; 30 | Button uploadbtn; 31 | public static final int CONNECTION_TIMEOUT = 50000; 32 | public static final int READ_TIMEOUT = 15000; 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | 37 | setContentView(R.layout.activity_register); 38 | username =(EditText)findViewById(R.id.txtuserame); 39 | password =(EditText)findViewById(R.id.txtpass); 40 | rpassword =(EditText)findViewById(R.id.txtrpass); 41 | 42 | firstname =(EditText)findViewById(R.id.txtfname); 43 | lastname =(EditText)findViewById(R.id.txtlname); 44 | address =(EditText)findViewById(R.id.txtAddress); 45 | cellno =(EditText)findViewById(R.id.txtCEllno); 46 | brokerno =(EditText)findViewById(R.id.txtBrokername); 47 | cnic =(EditText)findViewById(R.id.txtcnic); 48 | vehicleno =(EditText)findViewById(R.id.txtVehicleno); 49 | partyname =(EditText)findViewById(R.id.txtpartyname); 50 | 51 | 52 | 53 | 54 | } 55 | 56 | 57 | 58 | public void regtbn(View v){ 59 | if(password.getText().toString().isEmpty() || rpassword.getText().toString().isEmpty()) 60 | { 61 | Toast.makeText(register.this, "password is required!", Toast.LENGTH_LONG).show(); 62 | } 63 | else if(password.getText().toString().length()<4 || rpassword.getText().toString().length()<4){ 64 | Toast.makeText(register.this, "Password should contain atleast 4 characters!", Toast.LENGTH_LONG).show(); 65 | } 66 | else { 67 | 68 | //register.php?key=1234&username=ayesha&password=1234&cdate=2018-9-3 69 | 70 | if(password.getText().toString().equals(rpassword.getText().toString())){ 71 | Date c = Calendar.getInstance().getTime(); 72 | //System.out.println("Current time => " + c); 73 | 74 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 75 | String formattedDate = df.format(c); 76 | //Toast.makeText(register.this, formattedDate, Toast.LENGTH_LONG).show(); 77 | Uri.Builder builder = new Uri.Builder(); 78 | builder.scheme("https") 79 | .authority("mfenter.com") 80 | 81 | .appendPath("tracker") 82 | .appendPath("register.php") 83 | .appendQueryParameter("key","1234") 84 | .appendQueryParameter("username", username.getText().toString()) 85 | .appendQueryParameter("password", password.getText().toString()) 86 | .appendQueryParameter("cdate",formattedDate); 87 | 88 | 89 | String myUrl = builder.build().toString(); 90 | AsyncRetrieve as = new AsyncRetrieve(); 91 | as.execute(); 92 | as.u = myUrl; 93 | 94 | 95 | 96 | 97 | 98 | } 99 | else { 100 | Toast.makeText(register.this, "Passwords does not matched!", Toast.LENGTH_LONG).show(); 101 | } 102 | 103 | } 104 | 105 | } 106 | 107 | 108 | private class AsyncRetrieve extends AsyncTask { 109 | ProgressDialog pdLoading = new ProgressDialog(register.this); 110 | HttpURLConnection conn; 111 | URL url = null; 112 | String u; 113 | String res; 114 | 115 | //this method will interact with UI, here display loading message 116 | @Override 117 | protected void onPreExecute() { 118 | super.onPreExecute(); 119 | 120 | pdLoading.setMessage("\tCreating Account..."); 121 | pdLoading.setCancelable(true); 122 | pdLoading.show(); 123 | 124 | } 125 | 126 | // This method does not interact with UI, You need to pass result to onPostExecute to display 127 | @Override 128 | protected String doInBackground(String... params) { 129 | try { 130 | // Enter URL address where your php file resides 131 | url = new URL(u); 132 | 133 | } catch (MalformedURLException e) { 134 | // TODO Auto-generated catch block 135 | e.printStackTrace(); 136 | return e.toString(); 137 | } 138 | try { 139 | 140 | // Setup HttpURLConnection class to send and receive data from php 141 | conn = (HttpURLConnection) url.openConnection(); 142 | conn.setReadTimeout(READ_TIMEOUT); 143 | conn.setConnectTimeout(CONNECTION_TIMEOUT); 144 | conn.setRequestMethod("GET"); 145 | 146 | // setDoOutput to true as we recieve data from json file 147 | conn.setDoOutput(true); 148 | 149 | } catch (Exception e1) { 150 | // TODO Auto-generated catch block 151 | e1.printStackTrace(); 152 | Toast.makeText(register.this, e1.toString(), Toast.LENGTH_LONG).show(); 153 | return e1.toString(); 154 | 155 | } 156 | 157 | try { 158 | 159 | int response_code = conn.getResponseCode(); 160 | 161 | // Check if successful connection made 162 | if (response_code == HttpURLConnection.HTTP_OK) { 163 | 164 | // Read data sent from server 165 | InputStream input = conn.getInputStream(); 166 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 167 | StringBuilder result = new StringBuilder(); 168 | String line; 169 | 170 | while ((line = reader.readLine()) != null) { 171 | result.append(line); 172 | } 173 | 174 | // Pass data to onPostExecute method 175 | return (result.toString()); 176 | 177 | } else { 178 | 179 | return ("unsuccessful"); 180 | } 181 | 182 | } catch (Exception e) { 183 | 184 | // Toast.makeText(register.this, e.toString(), Toast.LENGTH_LONG).show(); 185 | e.printStackTrace(); 186 | return e.toString(); 187 | } finally { 188 | conn.disconnect(); 189 | } 190 | 191 | 192 | } 193 | 194 | // this method will interact with UI, display result sent from doInBackground method 195 | @Override 196 | protected void onPostExecute(String result) { 197 | pdLoading.dismiss(); 198 | 199 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 200 | 201 | if (result.toString().equalsIgnoreCase("1")) { 202 | // you to understand error returned from doInBackground method 203 | sharedpreferences = getSharedPreferences(MainActivity.mypreference, 204 | Context.MODE_PRIVATE); 205 | // Toast.makeText(register.this, "Registration Succesfull!", Toast.LENGTH_LONG).show(); 206 | SharedPreferences.Editor editor = sharedpreferences.edit(); 207 | editor.putString("username", username.getText().toString()); 208 | editor.putString("password", password.getText().toString()); 209 | editor.commit(); 210 | AsyncRetrieve1 as = new AsyncRetrieve1(); 211 | Uri.Builder builder = new Uri.Builder(); 212 | builder.scheme("https") 213 | .authority("mfenter.com") 214 | 215 | .appendPath("tracker") 216 | 217 | .appendPath("getauid.php") 218 | .appendQueryParameter("key", "1345") 219 | .appendQueryParameter("username", username.getText().toString()); 220 | 221 | 222 | String myUrl = builder.build().toString(); 223 | 224 | as.execute(); 225 | 226 | 227 | as.u = myUrl; 228 | 229 | } else { 230 | Toast.makeText(register.this, result.toString(), Toast.LENGTH_LONG).show(); 231 | 232 | } 233 | 234 | 235 | 236 | 237 | } 238 | 239 | /*t2.setText(result.toString()); 240 | SharedPreferences.Editor editor = sharedpreferences.edit(); 241 | editor.putString("id" , result.toString()); 242 | sendgps(); 243 | /* res = result.toString(); 244 | result.trim(); 245 | if(res.equalsIgnoreCase("Succeed") ){ 246 | 247 | Toast.makeText(login.this, "Log In Succesfull!", Toast.LENGTH_LONG).show(); 248 | } 249 | else { 250 | Toast.makeText(login.this, "Username or password is incorrect!", Toast.LENGTH_LONG).show(); 251 | }*/ 252 | 253 | } 254 | 255 | 256 | 257 | 258 | private class AsyncRetrieve1 extends AsyncTask { 259 | ProgressDialog pdLoading = new ProgressDialog(register.this); 260 | HttpURLConnection conn; 261 | URL url = null; 262 | String u; 263 | String res; 264 | 265 | public AsyncRetrieve1() { 266 | 267 | } 268 | 269 | //this method will interact with UI, here display loading message 270 | @Override 271 | protected void onPreExecute() { 272 | super.onPreExecute(); 273 | 274 | pdLoading.setMessage("\tUploading details.."); 275 | pdLoading.setCancelable(true); 276 | pdLoading.show(); 277 | 278 | } 279 | 280 | // This method does not interact with UI, You need to pass result to onPostExecute to display 281 | @Override 282 | protected String doInBackground(String... params) { 283 | try { 284 | // Enter URL address where your php file resides 285 | url = new URL(u); 286 | 287 | } catch (MalformedURLException e) { 288 | // TODO Auto-generated catch block 289 | e.printStackTrace(); 290 | return e.toString(); 291 | } 292 | try { 293 | 294 | // Setup HttpURLConnection class to send and receive data from php 295 | conn = (HttpURLConnection) url.openConnection(); 296 | conn.setRequestMethod("GET"); 297 | 298 | // setDoOutput to true as we recieve data from json file 299 | conn.setDoOutput(true); 300 | 301 | } catch (IOException e1) { 302 | 303 | // TODO Auto-generated catch block 304 | e1.printStackTrace(); 305 | return e1.toString(); 306 | } 307 | 308 | try { 309 | 310 | int response_code = conn.getResponseCode(); 311 | 312 | // Check if successful connection made 313 | if (response_code == HttpURLConnection.HTTP_OK) { 314 | 315 | // Read data sent from server 316 | InputStream input = conn.getInputStream(); 317 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 318 | StringBuilder result = new StringBuilder(); 319 | String line; 320 | 321 | while ((line = reader.readLine()) != null) { 322 | result.append(line); 323 | } 324 | 325 | // Pass data to onPostExecute method 326 | return (result.toString()); 327 | 328 | } else { 329 | 330 | return ("unsuccessful"); 331 | } 332 | 333 | } catch (IOException e) { 334 | 335 | 336 | e.printStackTrace(); 337 | return e.toString(); 338 | } finally { 339 | conn.disconnect(); 340 | } 341 | 342 | 343 | } 344 | 345 | 346 | 347 | // this method will interact with UI, display result sent from doInBackground method 348 | @Override 349 | protected void onPostExecute(String result) { 350 | pdLoading.dismiss(); 351 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 352 | 353 | // you to understand error returned from doInBackground method 354 | result.trim(); 355 | 356 | res = result.toString(); 357 | SharedPreferences.Editor editor = sharedpreferences.edit(); 358 | editor.putString("AUId", res); 359 | editor.putString("Approval","0"); 360 | editor.putString("username",username.getText().toString()); 361 | editor.commit(); 362 | login.approval=0; 363 | //Toast.makeText(register.this, res, Toast.LENGTH_LONG).show(); 364 | //insertdetails.php?key=1234&auid=108&fname=adeel&lname=khan&address=5-e%20NOrth%20karachi&cellno=94504890&vehicleno=859049&brokerno=8880&cnic=49508940329&pname=asjdkfl&pic=409jkalnocfsd 365 | Uri.Builder builder = new Uri.Builder(); 366 | builder.scheme("https") 367 | .authority("mfenter.com") 368 | 369 | .appendPath("tracker") 370 | .appendPath("insertdetails.php") 371 | .appendQueryParameter("key", "1234") 372 | .appendQueryParameter("auid", res) 373 | .appendQueryParameter("fname", firstname.getText().toString()) 374 | .appendQueryParameter("lname", lastname.getText().toString()) 375 | .appendQueryParameter("address", address.getText().toString()) 376 | .appendQueryParameter("cellno", cellno.getText().toString()) 377 | .appendQueryParameter("vehicleno", vehicleno.getText().toString()) 378 | .appendQueryParameter("brokerno", brokerno.getText().toString()) 379 | .appendQueryParameter("cnic", cnic.getText().toString()) 380 | .appendQueryParameter("pname", partyname.getText().toString()); 381 | String myUrl = builder.build().toString(); 382 | AsyncRetrieve2 as = new AsyncRetrieve2(); 383 | as.u = myUrl; 384 | as.execute(); 385 | 386 | 387 | 388 | } 389 | 390 | } 391 | private class AsyncRetrieve2 extends AsyncTask { 392 | ProgressDialog pdLoading = new ProgressDialog(register.this); 393 | HttpURLConnection conn; 394 | URL url = null; 395 | String u; 396 | String res; 397 | 398 | public AsyncRetrieve2() { 399 | 400 | } 401 | 402 | //this method will interact with UI, here display loading message 403 | @Override 404 | protected void onPreExecute() { 405 | super.onPreExecute(); 406 | 407 | pdLoading.setMessage("\tUploading details.."); 408 | pdLoading.setCancelable(true); 409 | pdLoading.show(); 410 | 411 | } 412 | 413 | // This method does not interact with UI, You need to pass result to onPostExecute to display 414 | @Override 415 | protected String doInBackground(String... params) { 416 | try { 417 | // Enter URL address where your php file resides 418 | url = new URL(u); 419 | 420 | } catch (MalformedURLException e) { 421 | // TODO Auto-generated catch block 422 | e.printStackTrace(); 423 | return e.toString(); 424 | } 425 | try { 426 | 427 | // Setup HttpURLConnection class to send and receive data from php 428 | conn = (HttpURLConnection) url.openConnection(); 429 | conn.setRequestMethod("GET"); 430 | 431 | // setDoOutput to true as we recieve data from json file 432 | conn.setDoOutput(true); 433 | 434 | } catch (IOException e1) { 435 | cancel(true); 436 | // TODO Auto-generated catch block 437 | e1.printStackTrace(); 438 | return e1.toString(); 439 | } 440 | 441 | try { 442 | 443 | int response_code = conn.getResponseCode(); 444 | 445 | // Check if successful connection made 446 | if (response_code == HttpURLConnection.HTTP_OK) { 447 | 448 | // Read data sent from server 449 | InputStream input = conn.getInputStream(); 450 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 451 | StringBuilder result = new StringBuilder(); 452 | String line; 453 | 454 | while ((line = reader.readLine()) != null) { 455 | result.append(line); 456 | } 457 | 458 | // Pass data to onPostExecute method 459 | return (result.toString()); 460 | 461 | } else { 462 | 463 | return ("unsuccessful"); 464 | } 465 | 466 | } catch (IOException e) { 467 | 468 | cancel(true); 469 | e.printStackTrace(); 470 | return e.toString(); 471 | } finally { 472 | conn.disconnect(); 473 | } 474 | 475 | 476 | } 477 | 478 | SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.mypreference, Context.MODE_PRIVATE); 479 | 480 | // this method will interact with UI, display result sent from doInBackground method 481 | @Override 482 | protected void onPostExecute(String result) { 483 | pdLoading.dismiss(); 484 | 485 | 486 | 487 | Toast.makeText(register.this, "Account Created!!", Toast.LENGTH_LONG).show(); 488 | Intent activityChangeIntent = new Intent(register.this, Approve.class); 489 | 490 | // currentContext.startActivity(activityChangeIntent); 491 | finishAffinity(); 492 | finish(); 493 | 494 | register.this.startActivity(activityChangeIntent); 495 | 496 | 497 | 498 | } 499 | 500 | }} 501 | 502 | 503 | 504 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/res/drawable/logo.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/logo1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/res/drawable/logo1.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/logochange.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/res/drawable/logochange.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/logoqurvex.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/res/drawable/logoqurvex.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/spl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madeel20/Vehicle-Tracking-System-AndroidApp-PHP/9590f38af481e09d614b3b1f67daa950aeb342cb/app/src/main/res/drawable/spl.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_approve.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 21 | 22 | 32 | 33 |