1

On my phone the app Bluetooth Share crashes randomly. With Tasker I want to be able to detect that crash, and then force close Bluetooth Share and finally launch Bluetooth Share again. (Or turn on Bluetooth again)

PS: I already have tasker and I am rooted on CM12.1.

Any help is appreciated. Thanks!

Thomas Vos
  • 4,000
  • 5
  • 35
  • 46
  • 1
    I could've tried posting an answer but I don't have any such app which crashes randomly. I would suggest watching logcat to see if the crashes has some intent or broadcast related info. If the crash doesn't relaunch the app then you may take a bit of help from this answer (hint: mFocusedActivity) – Firelord Jun 08 '15 at 15:40
  • Could Tasker Process Running (KC) allow you to detect when the app closes? https://play.google.com/store/apps/details?id=org.kc.tasker.processes – LJD200 Jun 11 '15 at 19:03
  • @LJD200 that app only checks if an app is running or not, it can't detect an app crash. – Thomas Vos Jun 11 '15 at 19:12
  • @SuperThomasLab Does this Bluetooth Share relaunches itself after crash or you have to manually do it again including enabling the on/off? Also, does this crash happen when it's running in background (when you're doing something else) or when it's in foreground? // Do you have any other app that behaves alike or do you want strictly a solution for Bluetooth Share only. (I can't test or create a solution unless I have such app)? – Firelord Jun 11 '15 at 19:15
  • @SuperThomasLab Do Android apps not close when they crash though? – LJD200 Jun 11 '15 at 19:17
  • To be able to turn on Bluetooth again, I first need to force stop it and then manually launch it again and I want to automate it with tasker. @Firelord – Thomas Vos Jun 11 '15 at 19:17
  • @Firelord Bluetooth Share does not fully close. – Thomas Vos Jun 11 '15 at 19:18
  • @SuperThomasLab Oh OK, sorrry. My mistake. – LJD200 Jun 11 '15 at 19:19
  • You can try keeping Bluetooth share resident in memory so that it never crashes. – Akhoy Jun 12 '15 at 11:10

2 Answers2

2

Unfortunately, it's quite not possible. Tasker cannot detect an app crash.

However, we can still do something about it.

Let's first make a profile that does the killing job. It will be executed when the bluetooth goes off.

  • Profile (name): BTrern

    • State (Context): BlueTooth Status [ Status:Off ] (Profile triggers when BT goes off)
    • Task: (You can give task a name)

      • A1: Kill App [ App:Bluetooth Share Use Root:On ]      (Click the + to add these actions)
      • A2: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]       (Wait for 5 seconds)
      • A3 (optional): [X] Launch App [ App:Bluetooth Share]       (If you need to launch it)
      • A4: Bluetooth [ Set:On ]     (Turns ON blutooth)`

Note: If killing even with root is not working (there could be some problem with your Tasker or root), you can try the following shell command:

am force-stop packagename

E.g.:

am force-stop com.google.android.apps.maps

Or if that doesn't work:

  • pm disable
  • Wait 3 seconds
  • pm enable

Now, the next question is how to turn off Bluetooth without executing the instructions noted above?

It's quite simple. Make another task.

  • Profile Status: BTrern → Off
  • Wait 5 seconds
  • Bluetooth → Off

Name this task (like BTOFF) and make a shortcut to your home screen.

Now whenever you want to turn off your BT use this shortcut.

Let's make another task that turns on BT as well as the BTrern

  • Bluetooth → ON
  • Wait 5 sec
  • Profile Status → BTrern : ON

Again, use the above two task shortcuts to turn BT ON or OFF.

You can also use a scene or a widget to make it even easier once you have acquired enough knowledge with Tasker..


OLD


I do not quite understand what you mean by Bluetooth share, but I would presume you mean the activity opened by Share → Bluetooth. May be a pic or two would help.

Instead of finding a way around, first try fixing it by:

  • Using a Log tool like catlog. (Open catlog → set it on Error, let the crash occur and then open catlog again and save the log.)
  • Searching for it. You haven't provided any info about your Android model so you might have to do it yourself.

In case those doesn't work, we can use Tasker. I believe the crash will occur within few seconds of opening the activity. We can use this to our advantage.

  • TRIGGER ON: (When Bluetooth Share activity opens)

    • If (Bluetooth Share activity close) AND (qtime < 5 sec)

      • start (Bluetooth Share activity)
    • else (goto 1)`

Here, qtime is a local variable which stores for how many seconds the task is running. You can find that in Help section of Tasker.

Also you can use Tasker Process Running (KC) for the required process.

Second Method:

Instead of that, it's much more easier to make a Scene instead of that.

  • Just make a small box with one button in it which will execute the activity. Keep it non - intrusive.
  • Scene1:

    • Kill Bluetooth Share process
    • Start Bluetooth Share process
  • TRIGGER ON: (When Bluetooth Share activity opens)

    • Create Scene1

      • If (Bluetooth Share activity close)

        • wait 5 seconds
        • destroy scene1

With this, there will be a small overlay when you open Bluetooth Share. If it crashes you can easily execute your kill and start command. And if it doesn't crash, the scene will get automatically destroyed after 5 seconds.

May be Bluetooth File transfer can help.

Firelord
  • 25,084
  • 20
  • 124
  • 286
Abhioxic
  • 514
  • 2
  • 8
  • Great answer, however ''Bluetooth Share'' crashes randomly. So not when I open an activity, share a file etc. I am going to try the logcat – Thomas Vos Jun 13 '15 at 15:18
  • To simply put, use a Scene to force-stop and relaunch Bluetooth Share. Btw, can you please be more clear what you mean by "Bluetooth share"? A Pic can say 1000 words! – Abhioxic Jun 13 '15 at 15:19
  • yes, and this is the "Bluetooth (share)" app: http://imgur.com/peB7kV7 – Thomas Vos Jun 13 '15 at 15:29
  • Bluetooth share is not only the sharing part, but the whole bluetooth app. It doesn't crash when I try to share a file, but it occurs randomly. And it is very annoying because I have an Android Wear device. I've got a Samsung Galaxy S4 with Cyanogenmod 12.1 and also look at my question on the Cyanogenmod forum here: http://forum.cyanogenmod.org/topic/110131-cm121-bluetooth-share-randomly-crashesstops-working/ – Thomas Vos Jun 13 '15 at 15:36
  • Here's the logcat: http://pastebin.com/jHPLxPGt – Thomas Vos Jun 13 '15 at 15:41
  • Not the data, I only have to force close it. – Thomas Vos Jun 13 '15 at 15:42
  • Ok, now i can understand it clearly
    As it says, its a nightly problem so you cannot fix it. so logcat wont work.

    As you have stated in your post, the only way except rebooting is to clear data and turn on bluetooth.

    Thus, in tasker instead of killing, use data clear and tuning bluetooth on.

    This should work now.

    – Abhioxic Jun 13 '15 at 15:44
  • Hello! Thanks for the detailed answer, but I don't understand this step Enter: Anon (43). Could you explain me what to do here? – Thomas Vos Jun 16 '15 at 07:21
  • I have edited to make it bit more human friendly. The Enter means that the task is an entry task. After Enter: is the name of the task. If i have named the task BTTSK it would show Entry: BTTSK. If you donot name it anything the default name Anon is used, which represents Anonymous. – Abhioxic Jun 16 '15 at 09:51
  • Tasker "detects" the crash successfully, however it fails when turning on Bluetooth, so there is still a problem with force closing Bluetooth. – Thomas Vos Jun 16 '15 at 17:45
  • When Bluetooth crashes, it keeps repeating the task indefinitely until I disable tasker. Please help – Thomas Vos Jun 16 '15 at 18:38
  • It does successfully "detects" the crash and turn Bluetooth on again, but it repeats the task and it will start again, and again, again... – Thomas Vos Jun 17 '15 at 06:46
  • Awesome, at-least we solved the main big problem! Now you can easily solve the tiny mini problems: Try

    am force-stop packagename
    
    eg. am force-stop com.google.android.apps.maps
    
    Or if that doesnt work
    pm disable
    Wait 3 seconds
    pm enable
    

    I dont recommend the "or" one as i havent tried it yet, i just noted it down in case i need. Anyways test with Wait 3 sec, first try without this command if that doesnt work add the wait command.

    – Abhioxic Jun 17 '15 at 09:46
  • Oh btw you can also use the Secure Settings Plugin, it will give a whole lot more freedom. Off topic: Just look at this TODOOOOOOOO LIST! – Abhioxic Jun 17 '15 at 09:49
  • It works now, thanks for helping me. The bounty is yours now! – Thomas Vos Jun 17 '15 at 12:22
  • I don't want to sound rude but your sense of formatting is horrible. You abused backticks to evade formatting your answer according to the structure the site understands. I have corrected the formatting but please, do not abuse the backticks (`). Also, is there still a genuine need for the older answer here? – Firelord Oct 17 '15 at 02:21
0
  • Profile context App: Bluetooth Share
  • Enter Task

    • A1: Stop
  • Exit Task

    • A1: Bluetooth Share

Is this what you want?

Firelord
  • 25,084
  • 20
  • 124
  • 286
rebane2001
  • 200
  • 11
  • Doesn't that only detect when Bluetooth is turned off. Maybe I should explain my reason why I want to detect a crash. On my phone Bluetooth crashes randomly. I want tasker to be able to force stop Bluetooth and then launch it again. I want to detect a crash because if I manually turn off Bluetooth that it stays of and doesn't turn on again. Is this detailed enough? – Thomas Vos Jun 12 '15 at 08:19
  • Understood, you could make rule only trigger when bluetooth is on – rebane2001 Jun 12 '15 at 08:26
  • But still, if you add a rule if Bluetooth is on. When I turn Bluetooth off then it will also get past the rule, won't it? – Thomas Vos Jun 12 '15 at 08:27
  • I don't think so, try it out and tell me if it worked – rebane2001 Jun 12 '15 at 08:29
  • OK, but can you make a detailed answer with the steps. I am new to tasker. Only got it for a week or so. For example I halve know what "A1" is. Thanks – Thomas Vos Jun 12 '15 at 08:30