简体   繁体   English

Android应用程序自动启动

[英]Android Application Auto Start

i am using adb command for install .APk file in android phone successfully. 我正在使用adb命令在Android手机中成功安装.APk文件。 Now i want to start application at the installation time i mean when .apk file is install in phone then run .Apk File run automatically. 现在我想在安装时启动应用程序,我的意思是将.apk文件安装在手机中然后运行.apk文件自动运行。 Please guide me.. Thank in advance... 请指导我..预先感谢...

this is possible. 这个有可能。 you can do that by alarm Manager. 您可以通过警报管理器执行此操作。

just start AlarmManager before executing command 只需在执行命令之前启动AlarmManager

public void installApp(Context context) {

        Intent receiverIntent = new Intent(context, AlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context.getApplicationContext(), 234324243, receiverIntent, 0);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                + 1000 * 10, pendingIntent);

        File file = new File(Shared.getInstance().getApkDirectory());
        if (file.exists()) {
            try {
                final String command = "pm install -r " + file.getAbsolutePath();
                Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", command});
                Shared.getInstance().showToast(context, "before wait");
                proc.waitFor();


            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

register broadcast reciver in manifest 在清单中注册广播接收器

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent i = new Intent(context, yourActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

The answer is no, you simply cannot do that. 答案是否定的,您根本无法做到这一点。 After installation user should manually launch your application. 安装后,用户应手动启动您的应用程序。

There is a way - you install an application firstly, which will monitor apk installations and launch them. 有一种方法-首先安装一个应用程序,它将监视apk安装并启动它们。 But it requires a separate application. 但这需要单独的应用程序。

Edit: This also no longer works in Ice-Cream Sandwich. 编辑:这也不再适用于冰淇淋三明治。

If the apk is yours (made by you), you can let your application boot up by receiving system's BOOT_COMPLETE action. 如果apk是您自己制作的(由您自己制作),则可以通过接收系统的BOOT_COMPLETE操作来启动应用程序。 Hope it's useful for you. 希望对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM