code

.apk를 처음 설치할 때 서비스를 시작하는 방법

codestyles 2020. 11. 11. 20:11
반응형

.apk를 처음 설치할 때 서비스를 시작하는 방법


내 응용 프로그램에는 UI 부분이 없으므로 응용 프로그램이 장치에 설치되는 즉시 서비스를 시작해야합니다. 나는 그것이 불가능하다는 대답이 많은 링크를 보았지만 분명히 가능하다고 생각합니다. 내 요구 사항을 충족하는 Android Market의 PlanB 응용 프로그램을 살펴보십시오 . 아래는 내가 시도한 방법 내 Manifest 파일이지만 서비스가 전혀 호출되지 않았습니다. 따라서 애플리케이션이 설치 될 때 서비스를 시작하는 가장 좋은 방법이 무엇인지 알려주세요.

최신 정보

나는 또한 android.intent.action.PACKAGE_ADDED다른 응용 프로그램에 대한 패키지를 감지하는 데 잘 작동하지만 자체적으로는 작동하지 않았습니다.

<?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>

다행히 Plan B는 XOOM 및 Galaxy Nexus에서 테스트 한대로 Android 3.1 이상에서 작동하지 않습니다.

플랜 B가하는 일은 드라이브 바이 멀웨어가 사용할 수있는 보안 허점을 악용하는 것입니다. 이것이 특히 Android가 더 이상 발생하지 않도록하는 이유입니다.


최신 정보

명확하게하기 위해 : inazaruk가 게시하고 다른 답변에 대한 의견을 남겼을 때 모든 응용 프로그램은 설치시 "중지됨"상태에 놓입니다. 이는 사용자가 설정 애플리케이션에서 앱을 강제 종료 한 후 애플리케이션이 종료되는 것과 동일한 상태입니다. 이 "중지"상태에있는 동안에는 활동을 수동으로 시작하는 경우를 제외하고는 어떤 이유로 든 애플리케이션이 실행되지 않습니다. 특히 BroadcastReceviers사용자가 앱을 수동으로 실행할 때까지 등록 된 이벤트에 관계없이 no 가 호출됩니다.

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".


Applications installed on the /system partition are not subject to being placed into the "stopped" state after installation. If you have root, you can do,

$ adb root
$ adb remount
$ adb push your.apk /system/app

And it can immediately receive broadcast intents. This certainly doesn't provide a general purpose solution, but i wanted to mention it for completeness.

EDIT: Keep in mind that different versions of Android locate system APKs in different places. For example, Android 8 puts them under /system/app//.apk. Shell into your device and poke around and follow the same scheme used for other system APKs.


I agree with CommonsWare's answer to question: How to start android service on installation. In other words, you can't automatically start your service after you've just been installed.

One more thing about newer Android platforms: if you don't have UI at all, you'll have trouble starting your service even when using BOOT_COMPLETE intent on Android 3.1+.

That's because all installed applications are in stopped state. In this state applications will not receive ANY broadcast notifications.

In order to activate your application some other application (or user) needs to start your service or activity, or content provider. The usual workflow is when user clicks on your application's icon.

I've written a detailed explanations about this in my blog post.


Plan B does this launch by listening to the events which happen in the system. It uses a receiver which literally listenes to hundreds of events hoping that some of them will eventually fire up. So this is how you can do it. Otherwise, there are no built-in means to launch the application as soon as it gets installed.


I'm not sure what your constraints/purpose is, but if you can install another application that has an activity you can have it send an intent with the flag FLAG_INCLUDE_STOPPED_PACKAGES.

This will use your application for the intent resolution, even though it's in a stopped state. If the action of the intent matches one of your filters, it will also bring the package out of the stopped state.


I don't think so You can start service immediately after installed your application on device,

The application must first be invoked by the user through some sort of Activity.The only things you have to register some Broadcast Receiver with appropriate intents in manifest which invoke you service when something is happening on device but this remaing to Android 3.1 version.

EDIT:

After Android 3.1+ onwards you can not use any Broadcast for starting your application, because all application remains in inactive state after completion of device boot and to launch the application the user have to invoke it.(By touching the app icon).


As stated by CommonsWare in the answer to this question (which I suppose you have all ready seen, but chose to ignore) starting a Service on install is not possible - it is simply not a thing that is implemented into the platform.

Starting it automaticly at the next boot is however possible.

As stated in the Technical Details for PlanB:

Plan B will attempt to launch as soon as it downloads, but in some cases you will need to send an SMS to get it started.

My guess is that on a rooted phone you might be able to start the Service on install - but there's no guarantee that the phone is rooted, which is why PlanB will require recieving a text in some cases because that can be registered by the IntentFilter of the app and then used to start the Service.


there is an app on google play Android Lost which invoke the registration service for google push messages via an incoming sms without launching the app even once for version 3.0+.


Perhaps the best way to accomplish this (and now I'm speaking to the specific intent of the OP, a program that gets installed in order to retrieve a stolen phone, not the general question) is social engineering, not software engineering.

So, an icon with text like "Password List" or "My Bank Accounts" which suddenly appeared on the home screen would undoubtedly be clicked on. Look at the success of all sorts of other phishing, and here you would be targeting a thief, who's already motivated to continue nefarious activity. Let the thief start it for you. :)


HEY I think using a BroadcastRecivier to automatically start the app on restart of device hence it will automatically start on device start.Hope this will help

참고URL : https://stackoverflow.com/questions/8531926/how-to-start-a-service-when-apk-is-installed-for-the-first-time

반응형