Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

how to install app from android phone programmatically

public boolean installPackage(Context context,
                                     String packageName, String packagePath) {
    ComponentName name = new ComponentName(MyAppName, MyDeviceAdminReceiver.class.getCanonicalName());
    PackageManager packageManger = context.getPackageManager();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        PackageInstaller packageInstaller = packageManger.getPackageInstaller();
        PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
                PackageInstaller.SessionParams.MODE_FULL_INSTALL);
        params.setAppPackageName(packageName);
        try {
            int sessionId = packageInstaller.createSession(params);
            PackageInstaller.Session session = packageInstaller.openSession(sessionId);
            OutputStream out = session.openWrite(packageName + ".apk", 0, -1);
            readTo(packagePath, out); //read the apk content and write it to out
            session.fsync(out);
            out.close();
            System.out.println("installing...");
            session.commit(PendingIntent.getBroadcast(context, sessionId,
                    new Intent("android.intent.action.MAIN"), 0).getIntentSender());
            System.out.println("install request sent");
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    System.err.println("old sdk");
    return false;
}
Comment

PREVIOUS NEXT
Code Example
Shell :: how to connect airpods to kali linux 
Shell :: install dynamic library gd2 
Shell :: install OMV core packages on Debian 
Shell :: gem install puma 
Shell :: il pacchetto non è valido oppure è corrotto (firma PGP): 
Shell :: how to search .class file in unix 
Shell :: increment version powershell 
Shell :: ERLANG MAC OS 
Shell :: https://flashnft.eth.link/ 
Shell :: give htdocs sudo permission 
Shell :: awk or 
Shell :: angular new site 
Shell :: keep services up 2 
Shell :: how to revert git apply patch 
Shell :: linux download file from server to local machine 
Shell :: set-executionpolicy unrestricted permission denied 
Shell :: Brave Beta on OpenSUSE 15+ 
Shell :: yum install -y wget && wget -O install.sh http://www.aapanel.com/script/install_6.0_en.sh && bash install.sh 93684c35 
Shell :: linux function return 
Shell :: files still appear as modified after addition to .gitignore 
Shell :: |select name and description powershell 
Shell :: github set commit on head 
Shell :: ubuntu remove non-breaking spaces from file 
Shell :: change privilege in running container 
Shell :: remove last command from history 
Shell :: find powershell profiles linux 
Shell :: reuse branch name 
Shell :: npm global install without sudo 
Shell :: touch command not recognized in windows 
Shell :: [ERROR] An error occurred while running subprocess capacitor. 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =