1. Are you ready for the Galaxy S20? Here is everything we know so far!

Is there possibility to "Auto-start" application when users become inactive?

Discussion in 'Android Development' started by Patryk Krawczuk, Sep 16, 2019.

  1. Patryk Krawczuk

    Thread Starter

    Hi,
    I have to create an app, which detects user inactivity, and then start activity which displays some videos with WebView, and then when displaying with WebView is finished, it has to play videos from SDCard. I've already handled part with WebView and SDCard (with JavaScriptInterface etc.)
    This application has to work with API 19 all the way to the newest one.

    The question is - Is there a possibility to detect if user is inactive and start my application, or keep the app running in background, and then start activity in the foreground after the user becomes inactive for certain time?

    I'm not trying to play ads, when user is not looking at his screen. Application is for my client, who have stores with all kind of electrical equipments, including smartphones. The goal is to play video presentations with hardware details specific for each smartphone (informations about processor, ram, camera, screen etc.).

    In short: I have to make an app which is similar to "Demo Apps" created for example by Samsung (playing some kind of presentations on screen).

    So far I've read and tested things like:

    1) BroadcastReceiver with combination of ACTION_SCREEN_OFF / ACTION_SCREEN_ON events.

    Receiver works properly, I can detect this event and then start activity, but... The screen is already off so i can't see the displayed activity - it's visible running in the foreground after unlocking the phone. Is there a way to unlock the phone when the event is received?

    That's my code so far.
    EventReceiver Class:
    Code (Text):
    1.  
    2. class EventReceiver: BroadcastReceiver() {
    3.    override fun onReceive(context: Context, intent: Intent) {
    4.        StringBuilder().apply {
    5.            append("Action: ${intent.action}\n")
    6.            append("URI: ${intent.toUri(Intent.URI_INTENT_SCHEME)}\n")
    7.            toString().also { log ->
    8.                Log.d(TAG, log)
    9.                Toast.makeText(context, log, Toast.LENGTH_LONG).show()
    10.            }
    11.        }
    12.  
    13.        if (intent.action == Intent.ACTION_SCREEN_OFF) {
    14.            val i = Intent(context, MainActivity::class.java)
    15.            context.startActivity(i)
    16.        }
    17.    }
    18. }
    19.  
    MainActivity Class:
    Code (Text):
    1.  
    2. val br : BroadcastReceiver = EventReceiver()
    3. val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION).apply {
    4.    addAction(Intent.ACTION_SCREEN_OFF)
    5.    addAction(Intent.ACTION_SCREEN_ON)
    6.    addAction(Intent.ACTION_BOOT_COMPLETED)
    7. }
    8.  
    2) Foreground Services - I read that this is a great way to make some asyc stuff in the background and show notifications to user. Is there a way to start the activity with it?

    3) Job Scheduler

    4) Daydream / Dream Service - it actually works great with almost every API and manufacturer, but.. there's no way to set the app as Screen Saver on Huawei/Honor smartphones, at least from phone settings, I've read that this is possible with ADB etc. but this is not an option that I can use here.

    It seems that none of these fullfill my expectations.
     


Loading...
Similar Threads - possibility Auto start
  1. Devang Shah
    Replies:
    0
    Views:
    120
  2. montecarlo1987
    Replies:
    14
    Views:
    494
  3. Xyberz
    Replies:
    2
    Views:
    712
  4. willsp28
    Replies:
    26
    Views:
    1,121
  5. Rgarner
    Replies:
    0
    Views:
    599
  6. louis2008
    Replies:
    1
    Views:
    376
  7. imsail
    Replies:
    5
    Views:
    371
  8. gutthatrat
    Replies:
    1
    Views:
    321
  9. TheOuz
    Replies:
    0
    Views:
    605
  10. Toks777
    Replies:
    2
    Views:
    511

Share This Page

Loading...