The app is getting an input number and has a button that makes the call. I want to save the input for later use and have tried used Shared preference.
public class MainActivity extends AppCompatActivity {
Button myButton = null;
EditText numberCall = null;
int PERMISSION_ALL = 1;
String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.CALL_PHONE};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
The button for making the call:
myButton = (Button) findViewById(R.id.button);
I want to save numberCall!
numberCall = (EditText) findViewById(R.id.editText);
asking for permission
if(!hasPermissions(this, PERMISSIONS)){
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OnCallBtnClicked();
}
});
}
making the call
private void OnCallBtnClicked() {
Integer num = Integer.valueOf(numberCall.getText().toString());
Intent call = new Intent(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:" +"0"+num));
startActivity(call);
}
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}