'How to get apk path on Android Studio while programmatically installing it on 4.2

I trying to install an apk on button click

I'm calling the apkInstall("netflix") like this then I have the apk files save under

res > old > netflix.apk

res > new > netflix.apk

public String apkInstall(String name){
 
            if(android.os.Build.VERSION.SDK_INT <= 18){
                Log.d("State", "initializing old");
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(new File
                        ("/src/main/res/old/"+name+".apk")), "application/vnd.android.package-archive");
                startActivity(intent);
                Log.d("End", "End old");
            }else{
                Log.d("State", "initializing new");
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(new File
                        ("src/main/res/new/"+name+".apk")), "application/vnd.android.package-archive");
                Log.d("intent", String.valueOf(intent));
                startActivity(intent);
                Log.d("End", "End new");
            }
} 

I'm getting these logs

2022-04-13 02:35:07.822 24733-24733/com.mtl.installer D/State: initializing new
2022-04-13 02:35:07.828 24733-24733/com.mtl.installer D/intent: Intent { act=android.intent.action.VIEW dat=file:///src/main/res/new/netflix.apk typ=application/vnd.android.package-archive }

and I can't reach the log "End" and I'm lost because there's no error

any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source