Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:58+00:00 2026-05-29T10:13:58+00:00

I’m trying to set a unique ID for a phone, but each time the

  • 0

I’m trying to set a unique ID for a phone, but each time the user initiates the button, it generates a new ID and sends it to the database. The app will track the user’s location and I’d like to set the ID once so that each time the tracking is initiated, the user will always have the same ID. Right now, the program will send the ID and it will stay the same each time it is sent. The problem however, occurs when a user goes back to the main screen, and returns to the screen to initiate tracking. Here is an example of events:

  1. User initiates tracking
  2. User goes back to main screen (original ID is lost)
  3. User returns to screen with button to initiate tracking
  4. User initiates tracking again (this generates a new ID)

I would like to retain the ID instead of generating a new one each time the user initiates tracking. Any thoughts on how to do this? Here is some code that may help.

public class SendAlert extends Activity {


    private Button help_button;
    private TextView latitude; 
    private TextView longitude;
    private TextView id;
    Button sendButton;
    EditText msgTextField;

    String uuid = UUID.randomUUID().toString();

    private LocationManager locManager;
    private LocationListener locListener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sendalert);

        SharedPreferences shared = getSharedPreferences("PEOPLE_PREFERENCES", MODE_PRIVATE);
        final String first = shared.getString("FIRSTNAME", "");
        final String last = shared.getString("LASTNAME", "");
        final long phone = shared.getLong("PHONE", 0);
        final String city = shared.getString("CITY", "");
        final int zip = shared.getInt("ZIP", 0);

        help_button = (Button)findViewById(R.id.button1);
        latitude = (TextView)findViewById(R.id.label_latitude);
        longitude = (TextView)findViewById(R.id.label_longitude);
        id = (TextView)findViewById(R.id.label_id);

        help_button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                startLocation();
                //id.setText(String.valueOf(uuid));

                sendId(first, last, phone, city, zip);
            }
        });
    }

    private void startLocation()
    {

        //We get a reference to the LocationManager
        locManager = 
            (LocationManager)getSystemService(Context.LOCATION_SERVICE);

        //We get the last known position
        Location loc = 
            locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        //We show the last known position
        showPosition(loc);

        //We checked to receive updates from the position
        locListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                showPosition(location);
            }
            public void onProviderDisabled(String provider){
                //labelState.setText("Provider OFF");
            }
            public void onProviderEnabled(String provider){
                //labelState.setText("Provider ON ");
            }
            public void onStatusChanged(String provider, int status, Bundle extras){
                //Log.i("", "Provider Status: " + status);
                //labelState.setText("Provider Status: " + status);
            }
        };

        locManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0, locListener);
    }

    private void showPosition(Location loc) {
        if(loc != null)
        {
            latitude.setText(String.valueOf(loc.getLatitude()));
            longitude.setText(String.valueOf(loc.getLongitude()));
            id.setText(String.valueOf(uuid));
            Log.i("", String.valueOf(loc.getLatitude() + " - " + String.valueOf(loc.getLongitude())));


            send(latitude);


        }
        else
        {
            latitude.setText("Latitude: No Data");
            longitude.setText("Longitude: No Data");
        }   
    }

    private void send(View v)
    {
        // get the message from the message text box
        //String msg = latitude.getText().toString() + "," + longitude.getText().toString(); s
        String lat = latitude.getText().toString(); 
        String lon = longitude.getText().toString(); 

        // make sure the fields are not empty
        //if (lat.length()>0)
        if (lat != "0" && lon != "0")   
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.example.com/receive.php");
         try {
           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); //changed to 4
           nameValuePairs.add(new BasicNameValuePair("lat", lat)); //changed "message" to "lat" changed "msg" to "lat"
           nameValuePairs.add(new BasicNameValuePair("lon", lon)); //added this line
           nameValuePairs.add(new BasicNameValuePair("id", uuid));
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           httpclient.execute(httppost);
           //msgTextField.setText(""); // clear text box
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
         } catch (IOException e) {
             // TODO Auto-generated catch block
         }

        }
        else
        {
            // display message if text fields are empty
            Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
        }

    }

    private void sendId(String first, String last, long phone, String city, int zip)
    {
        // get the message from the message text box
        String user_id = id.getText().toString(); 

        // make sure the fields are not empty
        //if (lat.length()>0)
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.example.com/receive_user.php");
         try {
           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); //changed to 4
           nameValuePairs.add(new BasicNameValuePair("id", user_id));
           nameValuePairs.add(new BasicNameValuePair("firstname", first));
           nameValuePairs.add(new BasicNameValuePair("lastname", last));
           nameValuePairs.add(new BasicNameValuePair("phone", Long.toString(phone)));
           nameValuePairs.add(new BasicNameValuePair("city", city));
           nameValuePairs.add(new BasicNameValuePair("zip", Integer.toString(zip)));

           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           httpclient.execute(httppost);
           //msgTextField.setText(""); // clear text box
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
         } catch (IOException e) {
             // TODO Auto-generated catch block
         }

        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:13:59+00:00Added an answer on May 29, 2026 at 10:13 am

    As a previous poster points out, you can access e.g. TelephonyManager and get a unique device identifier. However it is important to note that the presence of this information varies by device – the aforementioned TelephonyManager.getID() may return null.

    If your device is capable of telephony – and for example some tablets or phones currently without SIM are not – then it is likely to have an IMSI and IMEI which you could use as the basis for a unique ID. Best practice should be that you do NOT use this directly because it is personal information – perhaps use a hash or checksum of it.

    The advantage of the above, rather than a purely proprietary calculation, is the high chance of uniqueness of the ID – because the source (e.g. IMEI) is already known to be unique – and that it can be repeatably calculated on the fly rather than having to be stored anywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.