How To Use MTP-connected Devices

by Doug Gordon » Thu, 03 Mar 2011 01:48:04 GMT


Sponsored Links
 My app currently requires the user to manually copy certain files from 
their PC to their USB-mounted Android device where my app can open them 
and do its thing. But I'm already running into issues with users' 
devices that want to mount in this "MTP" mode, and I hear that the Xoom 
*only* supports MTP, etc.


So how can MTP be used to transfer files to the device that don't really 
fit into the "Media files" category, and how do I locate the directory 
from my app? What do getExternalStorageDirectory and getExternalFilesDir 
return for a device like the Xoom?


Doug Gordon
GHCS Software

--



Re: How To Use MTP-connected Devices

by FrankG » Thu, 03 Mar 2011 04:59:35 GMT


 Hi Doug,

I can imagine that this will be more an more a problem for
applications
like yours : You cannot know in which usb mode the target device is
currently,
as this is highly vendor/manufacturer specific. You would also run
into trouble
if the user will use pictbridge. And you also not able to trigger a
mode change
because the interface to this is also specific for the manufacturer.

Would be interessted to know whether XOOM only supports MTP, but --
how far I understood Dianne in the past -- it must be at least MTP
+ADB,
otherwise Android Market will not work ?

Good luck !

   Frank





-- 


Sponsored Links


Other Threads

1. Messengers

I know that with all t-mobile phones there is a maximum of 30 friends/
contacts/buddys on your list. Will android be able to provide the
entire buddy lisl or will it still be limited to 30? (ex. AIM buddy
list = 100, signing on to aim mobile = cuts list down to 30)

--~--~---------~--~----~------------~-------~--~----~

2. Gallery setUnselectedAlpha not resuming transparency (alpha) when unselected after being selected

Hello All,
I have a gallery with the setUnselectedAlpha option enabled. The
gallery is
set to automatically progress through the gallery items, each time one
is
selected it waits 2 seconds before moving to the next. Before it is
selected, it is transparent. When selected it loses it's transparency,
and
then when it become unselected again it does not return to
transparent!

I have seen at times immediately after closing another activity using
the
back button it will work, but it is not consistent or repeatable.
Perhaps
this is a problem only with the emulator?

Below is the source code: (I have also submitted this as a bug on
Google Code, but it doesn't seem Google actually reviews the bugs in
any reasonable timeframe...)

Gallery declaration:

final HomeGalImgAdapter hgia = new HomeGalImgAdapter(ctx);
final Gallery gal = new Gallery(ctx);
gal.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
gal.setAdapter(hgia);
gal.setSpacing(0);
gal.setUnselectedAlpha(0.3f);
gal.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long
arg3) {
gal.setSelection(arg2);
galType.setText(hgia.getRating(arg2));
galTitle.setText(hgia.getName(arg2));
galAuthor.setText(hgia.getAuthor(arg2));
hgia.pauseBeforeNext(gal);
}

public void onNothingSelected(AdapterView<?> arg0) {

    }
});

And the code for the image adapter:

public class HomeGalImgAdapter extends BaseAdapter {
        private Context myContext;

        private Integer[] myImageIds = {
                        R.drawable.test128_add_to_folder,
                        R.drawable.test128_calendar,
                        R.drawable.test128_chart_pie,
                        R.drawable.test128_clock,
                        R.drawable.test128_comments,
                        R.drawable.test128_info,
                        R.drawable.test128_mail_receive,
                        R.drawable.test128_process,
                        R.drawable.test128_rss,
                        R.drawable.test128_search,
                        R.drawable.test128_users
        };

        /** Simple Constructor saving the 'parent' context. */
        public HomeGalImgAdapter(Context c) { this.myContext = c; }

        /** Returns the amount of images we have defined. */
        public int getCount() { return this.myImageIds.length; }

        /* Use the array-Positions as unique IDs */
        public Object getItem(int position) { return position; }
        public long getItemId(int position) { return position; }

        /** Returns a new ImageView to
         * be displayed, depending on
         * the position passed. */
        public View getView(int position, View convertView, ViewGroup
parent) {
                ImageView i = new ImageView(this.myContext);

                i.setImageResource(this.myImageIds[position]);
                /* Image should be scaled as width/height are set. */
                i.setScaleType(ImageView.ScaleType.FIT_XY);
                /* Set the Width/Height of the ImageView. */
                i.setLayoutParams(new Gallery.LayoutParams(96, 96));
                return i;
        }

        private Gallery gal;
        private GregorianCalendar time1;
        public void pauseBeforeNext(Gallery _gal)
        {
                gal = _gal;

                time1 = new GregorianCalendar();
                final Handler uiThreadCallback = new Handler();
                final Runnable runInUIThread = new Runnable()
                {
                        public void run()
                        {
                                _showInUI();
                        }
                };
                uiThreadCallback.removeCallbacks(runInUIThread);
                new Thread()
                {
                        @Override
                        public void run()
                        {
                                _doInBackgroundPost();
                                uiThreadCallback.post(runInUIThread);
                        }
                }.start();

        }
        private long ElapsedMillis()
        {
                GregorianCalendar gc2 = new GregorianCalendar();
                // the above two dates are one second apart
                Date d1 = time1.getTime();
                Date d2 = gc2.getTime();
                long l1 = d1.getTime();
                long l2 = d2.getTime();
                long difference = l2 - l1;
                return difference;
        }
        private void _showInUI() {
                if (ElapsedMillis() > 2500)
                {
                        if ((gal.getSelectedItemPosition() + 1) ==
gal.getCount())
                                gal.setSelection(0);
                        else

gal.setSelection(gal.getSelectedItemPosition() + 1);
                }
        }

        private void _doInBackgroundPost()
        {
                try {
                        Thread.sleep(2500);
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
        }
--~--~---------~--~----~------------~-------~--~----~

3. Potential medical applications

4. Can't install an APK from the browser.

5. Vote: a device G1 for each ADC entrance

6. INSTALL_NON_MARKET_APPS

7. Other Languages?