Find the answer to your Linux question:
Results 1 to 6 of 6
Like Tree4Likes
  • 4 Post By Miven
I was forced to finally get a smartphone by my workplace as I absolutely need to do email on the road. Being a bit of a Linux nut, I got ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    322

    Android (Nexus4) and MTP finally works.


    I was forced to finally get a smartphone by my workplace as I absolutely need to do email on the road. Being a bit of a Linux nut, I got one with Android on it. Nice deelybob. It even makes fonecalls.

    At work, I take pictures of mechanical issues and send them around if I don't have the parts/time/etc available at that occasion. That way the next tech has a good idea of what to bring on next visit. I also have to get these pics and stuff off the fone, just in case something happens to it.

    Android doesn't do Mass Storage because that would disallow it from running when plugged in to USB. It does do MTP however, but in a strange way:

    After being plugged in to USB, the *first* mtp-* call always works, after that they all hang and do nothing. If you open the screen on the Nexus:
    Code:
    Connected as a Media Device
    
    USB Computer connection
    
    Connect as
    
    Media Device (MTP)  check
    
    Camera (PTP) no check
    you can tap twice on the MTP checkbox to disconnect and reconnect with the PC. Then you can do *one* mtp call. This is a pain, reconnecting after every mtp call.

    After some close perusing of libmtp and trying all kinds of things, I discovered that Android hates having its USB connection initialized and released. In libmtp, there is a directory called examples. Every single one of these commands inits the interface, does something, and then closes it.

    I got to thinking, "What if I open the interface, and sit in a loop, kinda like fdisk, waiting for user commands, and only close the interface when I'm done?"

    So I hacked mtp-connect. I called it mtp-connect-android at first, but when I saw how well it worked, I ported it to it's own little project, and called it mtpcondroid. It's purely CLI at this point (I might slap a ncurses list management interface on it if I get more motivated) but it works excellent.

    It lists the files on the device, folders, shows a folder/file tree, renames objects, gets files, sends files to specific folders, deletes objects, and creates new folders, as much as you want, all without resetting the interface. Pretty much everything you need. The only thing I have not been able to do is *move* objects around. At this point you need to get them, send them to the new location, and then delete the originals. An improvement I'm working on is to get and send whole directories.

    These are the dependencies:

    libusb
    libmtp
    glib
    readline (for filename completion and command history)
    ncurses (for readline)

    All pretty standard. One of the rockin features is that send-file has 2 modes. If you just want to send 1 file, you go:
    Code:
    s /path/to/file 53
    and it sends the file to folder 53 on the device. But, if you want to send ALL of you Chopin to the Music folder, you go:
    Code:
    s 1
    and then it loops on readline, and reads buffered terminal input line by line, so you can paste a huge blob of the output from
    Code:
    find mnt/Audio/mp3/C -name '*' | sort | less
    into it and it works! Even filenames with spaces in them.

    The tarball is all of 19k, and I post it here so others can take advantage of my efforts and play with it. It's still pretty crude, but it works for me.

    BTW my kernel is 2.6.6, and my OS is Mandrake10, now almost 10 years old. So this should work for anybody.

    Peace and Cheer.
    Attached Files Attached Files

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,380
    Nice! Good work. Does this work with Gingerbread? My android phone is one of the original Google Nexus One phones.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Guru rokytnji's Avatar
    Join Date
    Jul 2008
    Location
    Desert
    Posts
    3,966
    Quote Originally Posted by Rubberman View Post
    Nice! Good work. Does this work with Gingerbread? My android phone is one of the original Google Nexus One phones.
    My 4" tablet with Android 4.0 works as a Mass storage device/usb in my linux installs Rubberman. I never tried MTP yet. It is available though.
    My Wife has a Motorala Atrix 2 with Android 4.X that uses mtp but I am not allowed to play with it.
    Me. I got a Blackberry Storm and it uses mass storage device/usb tranfer also. Which is why I like and keep it. I watch old timey cartoons on it when not using as a phone or mp3 player. I think but am not sure MTP is a option also in BlackberryOS.

    So I wonder why Ginger Bread cannot be used as a mass storage device/usb tranfer? Also. Is MTP long range wireless transfer of files? I am kinda uneducated.
    I hope this thread teaches me.
    Linux Registered User # 475019
    Lead,Follow, or get the heck out of the way. I Have a Masters in Raising Hell
    Tech Books
    Free Linux Books
    Newbie Guide
    Courses at Home

  4. #4
    Linux Guru rokytnji's Avatar
    Join Date
    Jul 2008
    Location
    Desert
    Posts
    3,966
    Also. Is MTP long range wireless transfer of files? I am kinda uneducated.
    I hope this thread teaches me.
    Amazing what a country boy can learn when he takes a look see on his own.

    https://play.google.com/store/apps/d...airdroid&hl=en
    Linux Registered User # 475019
    Lead,Follow, or get the heck out of the way. I Have a Masters in Raising Hell
    Tech Books
    Free Linux Books
    Newbie Guide
    Courses at Home

  5. #5
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    322
    Yeah. I tried airdroid. I prefer not to use wireless if I can possibly get away with it. Plus it didn't work the way I wanted. I just wanted something simple and straightforward that used the stuff I already had. Plus the thing is sitting here charging beside my keyboard and I wanted to maximize that aspect. I *should* be able to use it as a modem at the same time.

    @rubberman: It should work with anything that does MTP, but I have a lack of stuff to test it on. Once again, I posted demonstration code that's half built but works for me. Most older MTP devices don't need to be reset everytime you close the connection.

    MTP is Media Transport Protocol. From my understanding, it was devised by MS to cater to teenage girls who just want to slap a few tunes on their dongle or zip a few pics off of it, and then grab it and run away. No courtesy mounting and unmounting. So it's a bit like FTP for dummies. It also allows the device to keep doing it's thing while you're using it's drivespace.

    @rokytnji: when you mount your 4" tablet with Android 4.0 as mass storage, does it shut down, or can you still use it like normal? I have a couple mp3 players that go braindead when plugged in, an old phone that does that too. If yours has an SD card then the chances are it just exports the SD card, not the whole phone. Even my Nexus4 just exports a subdirectory of the whole thing, kinda like exporting my $HOME dir.

    BTW, I don't seem to get email updates from this site anymore. I dunno.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,380
    "BTW, I don't seem to get email updates from this site anymore. I dunno. "

    Miven, have you checked your account settings? Anyway, good set of posts in this thread.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •