- Forum posts: 1
Apr 1, 2018, 1:56:12 PM via Website
Apr 1, 2018 1:56:12 PM via Website
Hey everyone
I just started writing the beginning of a program to get an IMSI number,
Upon setting the event of when pressing the button and using TelephonyServices
I get an error telling me I should give a warning before this action, and so I did choose that option, but now I got an error next to the word: "this"..
Does anybody know why?
enter code here
package com.example.yakir.myapplication;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button button;
TextView textView;
TelephonyManager td;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.checkConnectionButton);
textView = (TextView) findViewById(R.id.chechConnectionText);
td = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
textView.setText("IMSI number: " + td.getSubscriberId());
}
});
}
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.