Search in sources :

Example 1 with AppDataBase

use of org.flyve.mdm.agent.room.database.AppDataBase in project android-mdm-agent by flyve-mdm.

the class InstallAppActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // pending
    String status = "1";
    switch(requestCode) {
        case APP_INSTALL_REQUEST:
            if (resultCode == RESULT_OK) {
                FlyveLog.d("Package Installation Success");
                // installed
                status = "2";
            } else {
                FlyveLog.d("Installation failed");
            }
    }
    try {
        PackageManager packageManager = InstallAppActivity.this.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageArchiveInfo(appPath, 0);
        packageInfo.applicationInfo.sourceDir = appPath;
        packageInfo.applicationInfo.publicSourceDir = appPath;
        String appName = packageManager.getApplicationLabel(packageInfo.applicationInfo).toString();
        String appPackage = packageInfo.packageName;
        AppDataBase dataBase = AppDataBase.getAppDatabase(InstallAppActivity.this);
        if (dataBase.applicationDao().getApplicationById(id).length <= 0) {
            Application apps = new Application();
            apps.appId = id;
            apps.appName = appName;
            apps.appPath = appPath;
            // 1 pending | 2 installed
            apps.appStatus = status;
            apps.appPackage = appPackage;
            dataBase.applicationDao().insert(apps);
        } else {
            // update status to installed
            dataBase.applicationDao().updateStatus(id, "2");
        }
        if (status.equals("2")) {
            // remove notifications if exists
            NotificationManager notificationManager = (NotificationManager) InstallAppActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(Integer.parseInt(id));
        } else {
            Helpers.sendToNotificationBar(InstallAppActivity.this, Integer.parseInt(id), getString(R.string.app_pending_to_install), appName, true, MainActivity.class);
        }
    } catch (Exception ex) {
        FlyveLog.e(ex.getMessage());
    }
    finish();
}
Also used : PackageManager(android.content.pm.PackageManager) AppDataBase(org.flyve.mdm.agent.room.database.AppDataBase) NotificationManager(android.app.NotificationManager) PackageInfo(android.content.pm.PackageInfo) Application(org.flyve.mdm.agent.room.entity.Application) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

NotificationManager (android.app.NotificationManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 AppDataBase (org.flyve.mdm.agent.room.database.AppDataBase)1 Application (org.flyve.mdm.agent.room.entity.Application)1