This video shows the code to restrict the dual app functionality for your Android App. It seems that dual apps is an OS level functionality and most of the phone OEMs provide this functionality. There seems to be no direct API to restrict it. However, it can be done from the code of the App by checking the absolute path of the App’s files and directory.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.restrictdualappcreation;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
textView.setText(getFilesDir().getAbsolutePath());
if (this.getFilesDir().getAbsolutePath().contains("999")){
Toast.makeText(this, "Dual App not supported by this App", Toast.LENGTH_LONG).show();
finish();
}
else {
Toast.makeText(this, "This is not the Dual App", Toast.LENGTH_LONG).show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="329dp"
android:layout_height="197dp"
android:text="Hello World!"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.239" />
</androidx.constraintlayout.widget.ConstraintLayout>
Primary App (not the cloned one) opens up successfully:
Dual App (cloned app) opening is restricted: