0% found this document useful (0 votes)
2 views2 pages

User Location Activ Itty

The document is a Java class for an Android application that displays a user's car location using a WebView. It retrieves the user's employee ID from SharedPreferences and initializes a Firebase database reference for employee locations. The WebView is configured to enable JavaScript and handle console messages while loading a local HTML file to show the map.

Uploaded by

Atharva Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

User Location Activ Itty

The document is a Java class for an Android application that displays a user's car location using a WebView. It retrieves the user's employee ID from SharedPreferences and initializes a Firebase database reference for employee locations. The WebView is configured to enable JavaScript and handle console messages while loading a local HTML file to show the map.

Uploaded by

Atharva Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.example.

smartwastemanagement;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.Map;

public class UserCarLocationActivity extends AppCompatActivity {

private WebView webView;


private SharedPreferences sharedPreferences;
private DatabaseReference employeeLocationRef;
private String userEmployeeId;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_car_location);

sharedPreferences = getSharedPreferences("LoginPrefs", MODE_PRIVATE);


// Retrieve the user_employeeId from SharedPreferences
userEmployeeId = sharedPreferences.getString("user_employeeId",
"defaultEmployeeId");

// Initialize Firebase database reference


employeeLocationRef =
FirebaseDatabase.getInstance().getReference("EmployeeLocation");

// Set up WebView for showing the map


webView = findViewById(R.id.webViewCarLocation);

WebSettings webSettings = webView.getSettings();


webSettings.setJavaScriptEnabled(true);

// Set up WebViewClient to handle page loading and JavaScript execution


webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});

// Set up WebChromeClient to capture console messages from the WebView


webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onConsoleMessage(String message, int lineNumber, String
sourceID) {
Log.d("WebViewConsole", message + " -- From line " + lineNumber + "
of " + sourceID);
}
});

// Load the HTML file for displaying car location map


webView.loadUrl("file:///android_asset/user_map_car_location.html");
}

You might also like