If a particular application is launched, can't it have a similar effect, even if it's not a real shutdown?

Asked 2 years ago, Updated 2 years ago, 26 views

I am a college student who is trying to create an app lock application below.

You gave me a lot of good answers, so I found it quite difficult to steal events where certain apps run.

So I thought about what I could do to replace it.

Once you run the app, you can see the activities of my app on the screen after the app you created is turned on, and if you turn off my app, the app will also turn off

Once you run it, if you touch or other actions are performed once more in the app, you can float the activity as shown in number 1.

Run it once and continue sending it to onStop if it's the app

If it's hard to take away the priority of execution, I thought about how to prevent it after making it run. Once again, I would really appreciate it if you could advise me which method would be most realistic.

android

2022-09-21 16:55

1 Answers

When it comes to app lock apps https://play.google.com/store/apps/details?id=com.domobile.applock Are you talking about this kind of app? I downloaded it from the market and tested it, and the app lock works well.

If you're trying to implement something like this... (If I'm mistaken, let me know.)

Try AccessibilityService.

To use the Accessibility Service, AndroidManifest requires the following permissions:

<application>
    <service
        android:label="@string/accessibility_service_name"
        android:name=".WindowChangeDetectingService"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"/>
        </intent-filter>
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibilityservice"/>
    </service>
</application>

If the above permissions are included, the user must turn on accessibility permissions in the settings to operate. When a user turns on access, the apps run or change You can receive an Accessibility Event.

public class MyAccessibilityService extends AccessibilityService implements OnInitListener {

    private static final String LOG_TAG = "onAccessibilityEvent";

    @Override
    public void onServiceConnected() {
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) { 
    //If the app is launched, the Accessibility Event will come in here unconditionally. Why don't you check if it's the app here and if it's right, you can launch the app I set?
        AccessibilityNodeInfo source = event.getSource();
        if (source != null && source.getText() != null) {
            Log.i(LOG_TAG, source.toString());
            Log.i(LOG_TAG, source.getText().toString());
        }
    }


    @Override
    public void onInterrupt() {
        /* /* do nothing */
    }


    @Override
    public void onInit(int status) {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected boolean onKeyEvent(KeyEvent event) {
        return false;
    }
}

위와같은 방법으로 해보면 되지 않을까 싶어요. Acceeibility에 관한 간단한 예제소스를 참고해보세요.


2022-09-21 16:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.