Detect Installs from outside Playstore / Appstore

Is there a way to detect if our app is installed from outside appstore or playstore ??