自动安装Android应用程序 [英] Automatically install Android application

查看:134
本文介绍了自动安装Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要部署和更新各种企业应用程序提供给用户有限数量的Andr​​oid设备。

I need to deploy and update various enterprise applications to Android devices given to a limited number of users.

这些应用程序不应该在谷歌Play发布,但必须通过一个独立的频道发布。

These applications are not supposed to be published on Google Play but must be distributed via a separate channel.

我需要做的是企业包管理器的应用程序自动检查新的应用程序/更新,并自动触发安装新的或更新的APK没有先询问用户同意的。

What I need to do is an "enterprise package manager" application to automatically check for new apps/updates and automatically trigger installation of new or updated APKs without asking user consent first.

我知道,在设计上,Android的不允许第三方应用程序与安装的应用程序进行交互。我也知道根深蒂固的手机没有这个问题,因为你可以注入任何APK到设备中。

I know that, by design, Android doesn't allow 3rd party applications to interact with installed applications. I also know that rooted phones don't have this problem because you can inject any APK into the device.


  • 如果我煮安装为系统中的应用的企业包管理器的ROM(即使是基于CWM),但没有二进制(它仍然是一个企业的电话。 ..),将在该程序能够自动安装新的应用程序?

  • 我怎么不要求同意安装应用程序?我的意思是,我需要一个基本的code样品和权限,如果需要的话

  • 总之,做系统的应用程序以root身份运行的用户?我记得这么

  • If I cook a ROM (even based on CWM) with the "enterprise package manager" installed as system application, but without su binary (it's still an enterprise phone...), will that program be able to install new apps automatically?
  • How am I supposed to install an application without asking for consent? I mean, I need a basic code sample and permissions, if required
  • Anyway, do system apps run as root user? I remember so

推荐答案

如果您要检查您的应用程序,它是在你的服务器上的某个地方,你必须在每24小时检查更新一次,如果有可用的更新然后它会浏览到您的更新版本构建将得到安装异步任务

If you want to check for your application which is on somewhere on your server you have to check for Update in every 24 hour once, if there is any update available then it will navigate to the async task where your updated version build will get installed

public void checkforUpdate() {

        /* Get Last Update Time from Preferences */
        SharedPreferences prefs = getPreferences(0);
        lastUpdateTime = prefs.getLong("lastUpdateTime", 0);
        if ((lastUpdateTime + CommonString.timeCheckDuration) < System.currentTimeMillis() && System.currentTimeMillis()>lastUpdateTime) {
            // Asynch task
            new VersionCheckTask().execute();
        }
        else{
            // do nothing
        }
    }

现在将导航到:

private class VersionCheckTask extends AsyncTask<Void, Void, Void> {
        ProgressDialog progressDialog;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            try {
                progressDialog = new ProgressDialog(Login.this, android.R.style.Theme_Holo_Light_Dialog);
                //progressDialog.setTitle("AppName");
                progressDialog.setMessage("Checking for updates...");
                progressDialog.setCancelable(false);
                progressDialog.setIndeterminate(true);
                progressDialog.show();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        protected Void doInBackground(Void... params) {
            /**
             *  Simulates a background job.
             */
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("build",CommonString.buildVersion);
            map.put("en", CommonString.en);

            responce = CommonFunction.PostRequest("updateCheck", map);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (progressDialog != null && progressDialog.isShowing())
                progressDialog.dismiss();
            if(!CommonFunction.isNetworkAvailable()){
                Toast.makeText(ClaimColonyApplication.getAppContext(), CommonString.NO_NETWORK, Toast.LENGTH_SHORT).show();
                return;
            }
            ParseUpdateResponse(responce);
            if(rCodeUpdate == 100 && ApkLink.length() >0){
                new AlertDialog.Builder(Login.this,android.R.style.Theme_Holo_Light_Dialog)
                .setIcon(R.drawable.ic_launcher)
                .setTitle("Update Available")
                .setMessage(""+UpdateMessage)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                         //User clicked OK so do some stuff 
                        new VersionCheckTaskDialog().execute();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                         //User clicked Cancel 
                        finish();
                    }
                })
                .show();
            }else{
                if(rCodeUpdate == 100){
                    lastUpdateTime = System.currentTimeMillis();
                    SharedPreferences.Editor editor = getPreferences(0).edit();
                    editor.putLong("lastUpdateTime", lastUpdateTime);

                    editor.commit();
                }
            }
            super.onPostExecute(result);
        }
    }

    private class VersionCheckTaskDialog extends AsyncTask<Void, Void, Void> {
        ProgressDialog progressDialogUpdate;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            try {
                progressDialogUpdate = new ProgressDialog(Login.this, android.R.style.Theme_Holo_Light_Dialog);
                //progressDialog.setTitle("AppName");
                progressDialogUpdate.setMessage("Fetching updates...");
                progressDialogUpdate.setCancelable(false);
                progressDialogUpdate.setIndeterminate(true);
                progressDialogUpdate.show();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        protected Void doInBackground(Void... params) {
            /**
             *  Simulates a background job.
             */
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            String extStorageDirectory =    Environment.getExternalStorageDirectory().toString();
            File folder = new File(extStorageDirectory, "pdf");
            folder.mkdir();
            File file = new File(folder, "AppName."+"apk");
            try {
                    file.createNewFile();
            } catch (IOException e1) {
                    e1.printStackTrace();
            }
            /**
             * replace url to ApkLink
             */
             //DownloadFile(ApkLink, file);
             DownloadFile("URL", file);

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (progressDialogUpdate != null && progressDialogUpdate.isShowing())
                progressDialogUpdate.dismiss();
            if(!CommonFunction.isNetworkAvailable()){
                Toast.makeText(ClaimColonyApplication.getAppContext(), CommonString.NO_NETWORK, Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/pdf/" + "AppName.apk")), "application/vnd.android.package-archive");
                startActivity(intent);
                lastUpdateTime = System.currentTimeMillis();
                SharedPreferences.Editor editor = getPreferences(0).edit();
                editor.putLong("lastUpdateTime", lastUpdateTime);

                editor.commit();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                System.out.println("Exception in start intent for launch app-------: "+e.toString());
                e.printStackTrace();
            } 
            super.onPostExecute(result);
        }
    }

我在24小时内检查更新一次,如果有可用,那么它会显示弹出来,否则升级的应用程序将保存在preferences你上次检查任何时间更新。
现在,这将让你更新和安装应用程序,这在24小时后检查下次更新时,可能需要在条件下工作,以检查更新。请改变你的.apk文件和URL的名称。

I am checking for update once in 24 hours, if there is any update available then it will show pop up to upgrade your application otherwise will save your last checking time in Preferences. Now this will allow you to update and install your application and this will check for next update after 24 hours, you may need to work on conditions to check for update. Please change name of your .apk file and URL.

您将需要以下权限:

<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

好运。

这篇关于自动安装Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆