开发者

Android Application Auto Start

i am using adb command for install .APk file in android phone successfully. 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. Please guide me.. Thank in a开发者_开发知识库dvance...


If the apk is yours (made by you), you can let your application boot up by receiving system's BOOT_COMPLETE action. Hope it's useful for you.


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. But it requires a separate application.

Edit: This also no longer works in Ice-Cream Sandwich.


this is possible. you can do that by alarm Manager.

just start AlarmManager before executing command

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜