Android Open Source - adid-sender Main Activity






From Project

Back to project page adid-sender.

License

The source code is released under:

Copyright (c) 2011 Kiip Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software...

If you think the Android project adid-sender listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.kiip.android_id;
/* ww  w.j av  a2 s  .c o  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.text.ClipboardManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

    private static String ANDROID_ID_BUG = "9774d56d682e549c";
    private static String NULL_STRING = "(null)";

    private String mAndroidID,
                   mAndroidVersion,
                   mDevice;

    private Button mClipboardButton,
                   mEmailButton;

    private TextView mAndroidIDView,
                     mAndroidVersionView,
                     mDeviceView;

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

        mAndroidID = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        mAndroidVersion = "Android " + android.os.Build.VERSION.RELEASE;
        mDevice = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL + "/" + android.os.Build.DEVICE;

        // Check if the device is an emulator
        if (mAndroidID == null) {
            mAndroidID = NULL_STRING;
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Warning!")
                   .setMessage("The ANDROID_ID of an emulator will always show up as (null).")
                   .setCancelable(false)
                   .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                       @Override public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                       }
                   });
            AlertDialog alert = builder.create();
            alert.show();
        }

        // Check ANDROID_ID against bugged ANDROID_ID (9774d56d682e549c)
        if (ANDROID_ID_BUG.equals(mAndroidID)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Warning!")
                   .setMessage("The ANDROID_ID on your device is not unique.\n\nThis is an open bug in the Android platform.")
                   .setCancelable(false)
                   .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                       @Override public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                       }
                   });
            AlertDialog alert = builder.create();
            alert.show();
        }

        // Buttons
        mEmailButton = (Button)this.findViewById(R.id.email);
        mEmailButton.setOnClickListener(this);
        mClipboardButton = (Button)this.findViewById(R.id.clipboard);
        mClipboardButton.setOnClickListener(this);

        // TextView
        mAndroidIDView = (TextView)this.findViewById(R.id.android_id);
        mAndroidIDView.setText(mAndroidID);
        mAndroidVersionView = (TextView)this.findViewById(R.id.android_version);
        mAndroidVersionView.setText(mAndroidVersion);
        mDeviceView = (TextView)this.findViewById(R.id.device);
        mDeviceView.setText(mDevice);
    }

    @Override
    public void onClick(View v) {
        if(v.equals(mEmailButton)) {
            email();
        } else if(v.equals(mClipboardButton)) {
            clipboard();
        }
    }

    private void email() {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Device ANDROID_ID");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                mAndroidID + "\n\n"
                + mAndroidVersion + "\n"
                + mDevice);

        this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }

    private void clipboard() {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(mAndroidID);

        Toast.makeText(this, "'" + mAndroidID + "' copied to clipboard.", Toast.LENGTH_SHORT).show();
    }
}




Java Source Code List

me.kiip.android_id.MainActivity.java