LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Mobile
User Name
Password
Linux - Mobile This forum is for the discussion of all topics relating to Mobile Linux. This includes Android, Tizen, Sailfish OS, Replicant, Ubuntu Touch, webOS, and other similar projects and products.

Notices


Reply
  Search this Thread
Old 01-02-2014, 06:12 PM   #1
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Rep: Reputation: 22
Google Android Nexus 4 and MTP works... almost... [SOLVED]


So my work forced me to get a "smartphone". I scowled and objected, but finally caved in. I absolutely had to do email out on the road.

Well, the fone I got is a Nexus 4, apparently hand crafted by google with Android OS. It's actually pretty cool. I can even make fonecalls

The issue is getting stuff off it when I get home. It seems silly to email 3MB pix to myself when the thing is sitting here connected and charging off USB.

I tried Airdroid, some people praised it. It failed in that "Give Me Your Credit Card Number!" kinda way. adb does nothing. PTP and gphoto make my USB printer get excited but that's about all. Keep in mind I run old uber-hacked Mandrake10 with 2.6.6 kernel, so everything I do is compiled from source.

When I plug the fone in, log in as root, and go
Code:
mtp-files
sure enough, I get a file listing. But only once. After that, it's hang.......... until time-out, on any mtp command. I can only ever pull off *one* mtp command. I admit I have not investigated libmtp too much(yet).

What I discovered is that if I go to the fone's "USB computer connection" screen, it shows:
Code:
CONNECT AS

Media device (MTP) (check)

Camera (PTP) (no check)
If I tap that "Media device (MTP)" deelybob twice (eg. turn it off and then back on) my PC disconnects and reconnects, the devnum increments by one, and I can pull another mtp-* command. So, in order to retrieve 14 pix (and it has a very good camera) I use a script like this:
Code:
#!/bin/sh

if [ $UID -ne 0 ]; then
    echo "You must be root to run this script."
    exit 1
fi

function do_exit () {
    echo -e "\nDone."
    chown miven *
    chgrp miven *
    exit 2
}

trap do_exit 2

function readit () {
    read -p'Reset USB Computer Connection and hit <ENTER> ?'
}

readit

mtp-files > files

grep -1 'IMG.*jpg' files | grep -v 'File size' > jpgs

cat jpgs | \
    sed -e "s/^ *//" \
        -e "s/File ID: //" \
        -e "s/Filename: //" \
        -e "s/--/|/" | \
        tr '\n' ' ' | \
        tr '|' '\n' \
    > cmds

IFS=$'\n'
for line in $(cat cmds); do
    cmd="mtp-getfile $line"
    echo "-> $cmd"
    readit
    eval $cmd
done

do_exit
This allows me to do the tap-dance on the Android MTP check box in between every mtp call. This works. But, of course, it sucks.

I suppose my question is this:

Is there a way of forcing reset on the USB connection on the PC end, maybe a way of hacking libmtp, or is this completely on the Android end?

Peace and Cheer.

Last edited by mdooligan; 01-04-2014 at 10:22 AM.
 
Old 01-02-2014, 06:59 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
seems dependent on human intervention.

try sshdroid; i think you have to be rooted.

else you can scp from your fone to your pc using andftp.
 
Old 01-02-2014, 11:00 PM   #3
HyperX
LQ Newbie
 
Registered: Dec 2013
Posts: 9

Rep: Reputation: Disabled
@ mdooligan

I use Airdroid and it never ask for a credit card at any time and it works great.

Back on topic, have you tried File Expert HD? it's a cool file manager with tools to manage your files and it can act as a server and client. And it's FREE!
https://play.google.com/store/apps/d...?id=xcxin.fehd

File Expert HD has a built-in ftp server and you can try file transfers and see if it works for you.

Last edited by HyperX; 01-02-2014 at 11:02 PM.
 
Old 01-03-2014, 11:15 AM   #4
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Original Poster
Rep: Reputation: 22
I might try some of those apps, but I think I'm onto a nice solution involving stuff I already have:

It appears to me that libmtp goes wrong with the android in that it opens the usb connection, does something, then closes it. Android doesn't like this. It likes to open a *session*, do everything, and I'm not so sure it even cares about closing the session. This is mtp after all. It's designed for teenage girls who just want to slap a few tunes/pix on/off their fone and then yank it out and run. None of that courtesy mount/unmount stuff here.

I'm going to have a go a creating a modified mtp-connect, that opens the connection, and waits in a loop for instructions (getfile, files, filetree, delfile, etc), then closes when I'm finally done. Looking at the code, it shouldn't be much of a stretch.

Peace and Cheer.
 
Old 01-03-2014, 11:53 AM   #5
HyperX
LQ Newbie
 
Registered: Dec 2013
Posts: 9

Rep: Reputation: Disabled
Ok, I understand

It's a shame that android discontinue usb mass storage in place of MTP. Usb mass storage did what we wanted, connect our android device and then drop and drag our files to it. Those were the good ol' days...
 
2 members found this post helpful.
Old 01-03-2014, 11:57 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by HyperX View Post
Ok, I understand

It's a shame that android discontinue usb mass storage in place of MTP. Usb mass storage did what we wanted, connect our android device and then drop and drag our files to it. Those were the good ol' days...
i'm still holding onto my galaxy-s2...
 
Old 01-03-2014, 12:01 PM   #7
HyperX
LQ Newbie
 
Registered: Dec 2013
Posts: 9

Rep: Reputation: Disabled
Cool
 
Old 01-04-2014, 10:22 AM   #8
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Original Poster
Rep: Reputation: 22
Update

My technique works.

I hacked a version of mtp-connect, called it mtp-connect-android, and it runs in a loop, kinda like fdisk or something. I type "f <ENTER>" it shows the file listing of the device. Type "g 123" and it grabs File ID 123 and dumps it in the current directory as it's proper filename, eg "IMG_20131229_123112.jpg" or whatever.

I have to be logged in as root, but I can make as many mtp calls as I like without having to reset the device or USB connection. Awesome. It's pretty crude still, the code needs a lot of work, but it does work and proves my theory.

BTW, the reason these devices cannot be mounted as USB Mass Storage is so that they can continue working while plugged in. Ever remember mp3 players and stuff that essentially went dead when plugged in? You couldn't listen to music while charging? That's why. MTP allows the device to continue doing it's own thing while also allowing outside connection. Kinda like FTP server or something.

Peace and Cheer.
 
Old 01-10-2014, 10:39 PM   #9
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Original Poster
Rep: Reputation: 22
Update:

I'm slowly smoothing this hack over. I can get ranges like

g 145 153-157

and it will get file 145 and all the ones from 153 through 157, dump them in CWD.

The beauty of it is that I have 2 send modes:

s ~/bin/something 1

will send ~/bin/something to folder 1 (Music). But if I go

s 1

it notices the lack of from_path but catches the to_path, and sits in loop, so I can paste a huge chunk from

find /mnt/sda1/audio/mp3/C/ -name '*' | sort | less

into it. And it works! It chews the buffered terminal input (rxvt) and makes real send commands that work, and I get my Chopin and Corb Lund into the folder 1 on my device. It's fast too.

Life is good. I highly doubt that *doze stuff works this good. And Apps, well, there's a gajillion of them, and they never do what I want because they try to anticipate my needs, and always fail because I'm an old school hacker. There's a SMS and MMS grabber I use, and a feeble File Manager deelybob that seems to work, so far that's it for my Apps.

Simple MTP *works* with Android Nexus4. You just have to be crafty. In libmtp, you might notice that all of the mtp-* progs are in the dir /examples. That's great. They're examples of how the sh*t works. Learn. I have. Everyone wants stuff spoon fed, but, with all the changing tech, how can this be?

Peace and Cheer.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Spotted: Android 4.2.2 update for Google Nexus devices LXer Syndicated Linux News 0 02-13-2013 09:30 AM
LXer: With Google readying its own Nexus Chromebook, will it marry Chrome OS to Android? LXer Syndicated Linux News 0 11-28-2012 02:30 AM
LXer: Google Starts Rolling Out Android 4.0 To Nexus S LXer Syndicated Linux News 0 12-17-2011 10:50 AM
LXer: Samsung, Google said to be launching Nexus Two Android phone LXer Syndicated Linux News 0 11-01-2010 07:30 PM
LXer: Nexus One Could Torpedo Google Android Strategy LXer Syndicated Linux News 0 01-03-2010 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Mobile

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration