Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare Long type data in android studio

Tags:

java

android

I want to compare IMEI number in my phone with the data I declare, but the bug says: 'Operator == can not be applied to 'java.lang.String', 'long' How do I fix that?

MainActivity.java

public class MainActivity extends AppCompatActivity {

    TelephonyManager manager;
    private Button button;
    TextView textView;
    String IMEI;
    long IMEI2 = 356261058647361;

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

        button = (Button)findViewById(R.id.next);
        textView = (TextView)findViewById(R.id.textview1);

        manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        IMEI = manager.getDeviceId();

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                if(IMEI == IMEI2){
                    textView.setText("IMEI NUMBER : " + IMEI);

                }else{
                    textView.setText("data IMEI and IMEI2 did not match");
                }

            }
        });
    }

}
like image 414
borneo Avatar asked Dec 18 '22 01:12

borneo


2 Answers

if(IMEI.equals(String.valueOf(IMEI2)){
    textView.setText("IMEI NUMBER : " + IMEI);
}else{
    textView.setText("data IMEI and IMEI2 did not match");
}
like image 110
Rajan Kali Avatar answered Jan 09 '23 14:01

Rajan Kali


Try this

 button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                if(IMEI2.equals(""+IMEI){
                    textView.setText("IMEI NUMBER : " + IMEI);

                }else{
                    textView.setText("data IMEI and IMEI2 did not match");
                }

            }
        });
like image 32
Gowthaman M Avatar answered Jan 09 '23 16:01

Gowthaman M