如何启动服务时的apk安装是在第一次 [英] How to start a Service when .apk is Installed for the first time

查看:147
本文介绍了如何启动服务时的apk安装是在第一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我没有任何的用户界面的一部分,所以我需要尽快得到一个应用安装在设备启动服务。我看到很多环节,从这个问题的答案是,它不是可能的,但我想这肯定是可以的。只要看看 PlanB Android Market上的应用程序,它符合我的要求。下面是我的清单文件我多努力,但该服务不叫的。所以,让我知道了什么​​是开始,当应用程序被安装服务的最好的方式。

更新

我也尝试过使用 android.intent.action.PACKAGE_ADDED 它工作正常,检测包为其他应用程序而不是为自己。

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.auto.start
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <使用-SDK安卓的minSdkVersion =8/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED/>

    <应用
        机器人:图标=@可绘制/ ic_launcher>

        <服务机器人。为MyServiceNAME =>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /服务>

        <接收机器人:BootU preceiverNAME =>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
                <类机器人:名称=android.intent.category.DEFAULT/>
                <作用机器人:名称=android.intent.action.PACKAGE_INSTALL/>
                <作用机器人:名称=android.intent.action.PACKAGE_ADDED/>
                <数据机器人:计划=包/>
            &所述; /意图滤光器>
        < /接收器>
    < /用途>
< /舱单>
 

解决方案

幸运的是,B计划不会在Android 3.1+工作,因为测试的一个XOOM和Galaxy Nexus的。

什么B计划所做的是利用这一点,可以使用驱动器恶意软件安全漏洞,这是具体为什么Android的prevents这样的事情发生了。


更新

要澄清:由于inazaruk贴,我投入在其他的答案,所有的应用程序,安装后的意见,被放置在一个停止状态。这是应用程序中之后,用户强制停止从设置应用该应用卷起相同状态。而在这种停止状态,应用程序将不会以任何理由运行,除非手动推出的活动。值得注意的是,没有 BroadcastReceviers 将被调用,而不管他们所登录的事件,直到用户手动运行该应用程序。

该模块涵盖了B计划的情况远程安装和运行的运行,他们被pviously以$ P $的优势。毕竟,与,任何人只要有一个黑客攻击谷歌帐户是在有他们的设备感染的风险,免提因为它是。

所以,OP时说:

  

我需要尽快启动服务为的一个应用被安装在设备

在OP将不会成功,就需要重新设计应用程序,以避免这种所谓的需要。

In my Application I am not having any UI part, so I need to start a Service as soon as the Applicaton gets installed on the Device. I saw many links from which the answer was that its not possible but I guess it is surely possible. Just have a look at PlanB Application on the Android Market that does fulfil my requirement. Below is my Manifest file how I tried, but the Service was not called at all. So, let me know what is the best possible way to start a Service when the Application gets Installed.

UPDATE

I also tried using android.intent.action.PACKAGE_ADDED it works fine for detecting the Package for the other Applications but not for itself.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.auto.start"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
        android:icon="@drawable/ic_launcher" >

        <service android:name=".MyService">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </service>

        <receiver android:name=".BootUpReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <action android:name="android.intent.action.PACKAGE_INSTALL" />
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>

解决方案

Fortunately, Plan B does not work on Android 3.1+, as tested on a XOOM and a Galaxy Nexus.

What Plan B does is exploit a security hole that could be used by drive-by malware, which is specifically why Android prevents it from happening anymore.


UPDATE

To clarify: As inazaruk posted and I put into comments on other answers, all applications, upon installation, are placed in a "stopped" state. This is the same state that the application winds up in after the user force-stops the app from the Settings application. While in this "stopped" state, the application will not run for any reason, except by a manual launch of an activity. Notably, no BroadcastReceviers will be invoked, regardless of the event for which they have registered, until the user runs the app manually.

This block covers the Plan B scenario of remote-install-and-run, which they were taking advantage of previously. After all, with that, anyone with a hacked Google account would be at risk of having their device infected, hands-free as it were.

So, when the OP says:

I need to start a Service as soon as the Applicaton gets installed on the Device

the OP will be unsuccessful and will need to redesign the application to avoid this purported "need".

这篇关于如何启动服务时的apk安装是在第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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