this post was submitted on 22 Mar 2024
15 points (100.0% liked)

Android

27863 readers
30 users here now

DROID DOES

Welcome to the droidymcdroidface-iest, Lemmyest (Lemmiest), test, bestest, phoniest, pluckiest, snarkiest, and spiciest Android community on Lemmy (Do not respond)! Here you can participate in amazing discussions and events relating to all things Android.

The rules for posting and commenting, besides the rules defined here for lemmy.world, are as follows:

Rules


1. All posts must be relevant to Android devices/operating system.


2. Posts cannot be illegal or NSFW material.


3. No spam, self promotion, or upvote farming. Sources engaging in these behavior will be added to the Blacklist.


4. Non-whitelisted bots will be banned.


5. Engage respectfully: Harassment, flamebaiting, bad faith engagement, or agenda posting will result in your posts being removed. Excessive violations will result in temporary or permanent ban, depending on severity.


6. Memes are not allowed to be posts, but are allowed in the comments.


7. Posts from clickbait sources are heavily discouraged. Please de-clickbait titles if it needs to be submitted.


8. Submission statements of any length composed of your own thoughts inside the post text field are mandatory for any microblog posts, and are optional but recommended for article/image/video posts.


Community Resources:


We are Android girls*,

In our Lemmy.world.

The back is plastic,

It's fantastic.

*Well, not just girls: people of all gender identities are welcomed here.


Our Partner Communities:

[email protected]


founded 1 year ago
MODERATORS
 

I have an Android app which needs to run an overlay activity with some content in it over other apps on the phone at the moment they start or get focused. For this, I use AccessiblityService:

    override fun onAccessibilityEvent(event: AccessibilityEvent) {
        if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
           if (cond1) {
              
              // (!)
              // this will get triggered properly
              //

             val intent = Intent(this, MyOverlayActivity::class.java)
             intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP


             startActivity(intent)
           }
        }
    }

However, it'll only get launched properly whenever I switch to my own activity - MainActivity.

What's the matter?

MyOverlayActivity:

    class MyOverlayActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)

            // 1
    //        window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
    //        val layoutParams = WindowManager.LayoutParams(
    //            WindowManager.LayoutParams.MATCH_PARENT,
    //            WindowManager.LayoutParams.MATCH_PARENT,
    //            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
    //            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
    //            PixelFormat.TRANSLUCENT
    //        )
    //        window.attributes = layoutParams
            //



            // 2
            window.setFlags(
                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            )
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
            window.setLayout(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT
            )
            window.setGravity(Gravity.BOTTOM)
            //


            setContentView(R.layout.activity_my_overlay_layout)
        }
    }

Manifest


    <!-- [.............] -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <!-- [.............] -->

    <activity android:name=".MyOverlayActivity"
        android:exported="true"
        android:theme="@style/AppTheme.TranslucentNoTitleBarFullscreen"
        android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboardHidden|keyboard|navigation">
    </activity>

Note I've given the permission required to my app in Acessibility.

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here