benbahrenburg / benCoding.Android.Tools

A collection of utilities designed to make working with Titanium on Android alittle easier.
Other
59 stars 36 forks source link

BootReceiver: sendToBack meta-data doesn't work! #11

Open carlosrd opened 9 years ago

carlosrd commented 9 years ago

Hi!

I've tried the BootReceiver function included on Android.Tools but it doesn't work as I expected. There is an option in the meta-data parameters to set the restart to background or foreground (sendToBack).

The problem is it doesn't matter the value on sendToBack: Always restart the app on foreground!

<receiver android:exported="true" android:name="bencoding.android.receivers.BootReceiver">

     <intent-filter>
         <action android:name="android.intent.action.BOOT_COMPLETED"/>
         <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
    </intent-filter>

    <meta-data android:name="bootType" android:value="restart"/>
    <meta-data android:name="sendToBack" android:value="true"/>

</receiver>

I tested the app on a Nexus 4 running Android 4.4.2 and I used Titanium SDK 3.4.1 to develop it.

benbahrenburg commented 9 years ago

It looks as though Titanium no longer supports this behavior has it causes an application crash. It works in a purely native app though. If anyone has an idea on how to work around this crash please let me know and I'm happy to accept a PR.

EthraZa commented 9 years ago

It just bite me today! I got around like this:

index.js

function isBootTime() {
    var fl = Ti.Filesystem.getFile('file:///proc/uptime'), b, t;

    try {
        if (fl && ( b = fl.read())) {
            t = b.text.split(' ')[0];
            fl = b = null;
            return (t < 60);
        }
    } catch(er) {
    }

    return false;
}

if (isBootTime()) {
    return $.win.close();
}
julien9999 commented 7 years ago

Hi, any news on that ? Still seems to not be working. Thanks

deckameron commented 7 years ago

@julien9999 Have you tried this one? https://github.com/azwan082/nc-boot-completed

You could edit it and adapt to your needs. :)

ramonthegreat commented 5 years ago

@benbahrenburg ,

It looks as though Titanium no longer supports this behavior has it causes an application crash. It works in a purely native app though.

You're right. I read an article from the docs https://docs.appcelerator.com/platform/latest/#!/guide/Android_Broadcast_Intents_and_Receivers stating ,

Note that Titanium only supports programmatically creating and registering broadcast receivers. Titanium does not support declaring a receiver in the Android manifest.

I know this is old, but do you happen to know any remedy for this?