Register User in App

Adam4 years ago

Hello
I would like to see if a user can be registered from the mobile application (Using an activity and api/users)
Regards
Seba G

Anton Tananaev4 years ago

It is possible to do, but we currently don't use native Android code in Traccar Manager.

Adam4 years ago

Look, I´ve tried to do it but it throws a fatal error, I´ll leave you the code to see if I´m right or wrong

Code Extract:

                User user= new User();
                user.setName(nameInput.getText().toString());
                user.setEmail(emailInput.getText().toString());
                user.setPassword(passwordInput.getText().toString());

                final MainApplication application = (MainApplication) getActivity().getApplication();
                final WebService service = application.getService();
                Call<User> creatUser = service.createUser(user);  (ERROR FATAL - HERE)
                creatUser.enqueue(new Callback<User>() {
                    @Override
                    public void onResponse(Call<User> call, Response<User> response) {
                        try{
                            Log.e(TAG, "onResponse:" + response.body());
                        }catch (Exception ex){
                            Toast.makeText(getContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                    @Override
                    public void onFailure(Call<User> call, Throwable t) {
                        Log.e(TAG, "onFailure:" + t.getLocalizedMessage());
                    }
                });