I have an SDK that contains MYSDKActivity. In this activity layout, I have 1 edit text where the user can enter his card number. Any android Client who is integrating this SDK, can use ActivityLifecycleCallbacks in their application class and register text watcher on this edit text and can listen to user card number input.
I want to prevent SDK's edit text usage via the Application class. Only my SDK can access this edit text and perform some action. I want to block usage outside my SDK.
public class MyDemoApp extends Application implements Application.ActivityLifecycleCallbacks {
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(this);
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {}
@Override
public void onActivityStarted(@NonNull Activity activity) {}
@Override
public void onActivityResumed(@NonNull Activity activity) {
if (activity instanceof MYSDKActivity) {
final TextInputLayout textInputLayout = activity.findViewById(R.id.my_sdk_edit_text);
if (textInputLayout != null) {
ViewGroup textInputLayoutViewGroup = ((ViewGroup) textInputLayout.getChildAt(0));
for (int i = 0; i < textInputLayoutViewGroup.getChildCount(); i++) {
View child = textInputLayoutViewGroup.getChildAt(i);
if (child instanceof TextInputEditText) {
Log.v("USER Input", ((TextInputEditText) child).getText().toString());
((TextInputEditText) child).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.v("USER Input", s.toString());
}
@Override
public void afterTextChanged(Editable s) {}
});
}
}
}
}
}
}