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();
}
Aggregations