Tasker: Set USB for file transfer automatically

I have been shooting more and more videos with my Pixel 3 recently which means that all these files have to go somewhere. I acquired a USB-C expansion card to my PC to speed up the transfer process (review is coming). There was one thing left to make the process quicker and less painful: using Tasker to set USB for file transfer automatically.

Set USB for file transfer automatically with Tasker

The way Android storage is accessed via PC has changed over the years. It was much easier (and less secure in the past) now, the default way is simply annoying. I appreciate the security as any other guy, but c’mon Android, you could do it better! It was time to do what I’m doing best and use Tasker to set USB for file transfer automatically.

As soon as the Nav Bar Action has been released, I knew I would use this for that purpose. Android 9.0 is perfect for the nav bar modifications as it leaves a lot of space in the right corner. With the plan in mind, it was time to shape up Tasker’s behaviour.

You will need the following plugns to make it happen:

Trigger

TASKER PROFILE: USBFS Trigger
Profile: USBFS TRIGGER 
State: AutoNotification Intercept #
         [ Configuration:Notification App: Android system
           Notification Title: USB debugging connected ]
Enter: USBFS Connected+ 
    A1: Navigation Bar 
        [ Left:back[1.0] 
          Center:home[1.0] 
          Right:task(USBFS Set File=:=USBFS Connected-)[1.0] ] 

Exit: USBFS Connected- 
    A1: Navigation Bar 
        [ Left:back[1.0] 
          Center:home[1.0] 
          Right: ] 

Since I’m going to use AutoNotification plugin anyway, I opted out for notification monitoring rather than the USB trigger as an option. This way I only going to enable, then a correct device is plugged in.

When the notification is preset, Tasker will show me an extra navbar button which will:

  • [tap once] enable file sharing
  • [tap two] close the option

It’s possible to add the third tap, but I barely use any options. If you wish you can add the task to trigger MIDI, PTP or USB tethering.

I will need two actions, one to create the navbar button, and one to restore the original navbar button.

Action: Set USB for file transfer automatically

TASKER TASK: USBFS Set File transfer
USBFS Set File Sharing
    A1: AutoNotification Actions 
        [ Configuration:Notification Title: 
          Charging this device via USB Timeout (Seconds):20 ] 
    A2: AutoTools Secure Settings 
        [ Configuration:Set Accessibility Services: true
          Accessibility Services: com.joaomgcd.autoinput/com.joaomgcd.autoinput.service.ServiceAccessibility 
          Timeout (Seconds):60 ] 
    A3: AutoInput Action 
        [ Configuration:Type: Text
          Value: File transfer
        Action : Click Timeout (Seconds):20 ] 
        //OPTIONAL WAY//
    A4: [X] Keyboard [  Input:Tab Time Between Inputs:50 ] 
    A5: [X] Keyboard [  Input:Tab Time Between Inputs:50 ] 
    A6: [X] Keyboard [  Input:Tab Time Between Inputs:50 ] 
    A7: [X] Keyboard [  Input:Enter Time Between Inputs:50 ] 

    A8: Navigation Bar [ Left:back[1.0] Center:home[1.0] Right: ] 
    A9: AutoTools Secure Settings 
        [ Configuration:Set Accessibility Services: true 
          Timeout (Seconds):60 ] 
    A10: Go Home [ Page:0 ]

Initially, I wanted to use the new Keyboard action to toggle between on-screen options, but the method was much slower than AutoInput. (UPDATE: Joao corrected me, all the Tab and Enter keys can be entered as a single action which will speed things up). If you don’t want to use AutoInput (I’m going to use AutoTools to enable and disable the accessibility services to avoid the lag) you can use the keyboard action. It is slow.

To access the USB preferences screen, I’m using AutoNotification Action. This way I can simply “tap” on the message in my notification drawer which will open the correct setting’s menu.

Keyboard action way
To access the correct setting, you have to perform 4 actions:

  • Tab
  • Tab
  • Tab
  • Enter

Keep the delay to min  (50). 

First, enable the AutoInput accessibility using AutoTools Secure Settings, then using AutoInput automated setup navigate to the setting screen and tap on your preferred option. Return to the notification created by the AutoInput and finish up the task.

Since the AutoInput is no longer needed, toggle it back to off with AutoTools Secure Settings and modify the navbar to default values. Lastly, for the clean effect, navigate to the home screen.

Putting it back together

Once you can set USB for file transfer automatically, add the task to the navbar action when prompted to add another, link the task responsible for resetting the navbar to the default state and you are ready to go.

Conclusion

I should have set this up much sooner if I’m honest. It was easier than expected with AutoNotificaiton, and thanks to the AutoTools toggles AutoInput is not running constantly. Now I can set USB for file transfer automatically. It’s not a flashy profile, but something tells me it will be one of the most useful ones for sure.

You can download the files from this link. If you like my work, you can always buy me a coffee via PayPal, or join Patreon to gain additional rewards including early access to files and videos.

Liked it? Take a second to support Pocketables on Patreon!

Mat Zolnierczyk

I am passionate about technology, cycling, and art. This would explain why my bike has more computing power than your average office. I own notenoughtech.com and I write for xda-developers.com and pocketables.com NotEnoughTECH | Facebook | Twitter |YouTube |Instagram | Google+ |Donate |Patreon