Conversion between a URI and a string

Source: Internet
Author: User
There is a problem today:
Java code   Mringtonemanager.settype (ringtonemanager.type_alarm);    cursor mcursor = mringtonemanager.getcursor ();    if (mcursor != null) {                if (Mcursor.movetofirst ()) {                    do{                        LOG.D ("mCursor11111",  Mcursor.getstring (0));                         LOG.D ("mCursor22222",  mcursor.getstring (1));                         LOG.D ("mCursor33333",  mcursor.getstring (2));                        LOG.D (" mCursor44444 ",  mcursor.getstring (3));                    } while (Mcursor.movetonext ());                }             }  
Mringtonemanager.settype (ringtonemanager.type_alarm);
Cursor mcursor = Mringtonemanager.getcursor ();
if (mcursor!= null) {
			if (Mcursor.movetofirst ()) {
				do{
					log.d ("mCursor11111", mcursor.getstring (0));
					LOG.D ("mCursor22222", mcursor.getstring (1));
					LOG.D ("mCursor33333", mcursor.getstring (2));
					LOG.D ("mCursor44444", Mcursor.getstring (3));
				} while (Mcursor.movetonext ());
			}
		}

Because I don't know the field values of the database, I print them all,
The second value was found to be Content://media/internal/audio/media
The third value is Rooster Alarm
So take it for granted that two values are spliced Content://media/internal/audio/media/rooster Alarm
So the following conversion
Java code Uri u = Uri.parse ("Content://media/internal/audio/media/rooster Alarm"); Mmediaplayer.setdatasource (Context,u);
Uri u = uri.parse ("Content://media/internal/audio/media/rooster Alarm");
Mmediaplayer.setdatasource (Context,u);


Finally reported the following error:
Java.lang.NumberFormatException:unable to parse ' Content://media/internal/audio/media/rooster Alarm ' As Integer
Baffled
In addition to the URI this thing is also confused, no good information for the time being found
The most important question is: Can the URI be converted to a specific local file address. For example, Content://media/internal/audio/media/rooster Alarm can be converted into/mnt/sdcard/rooster Alarm.mp3.
This is a lot of questions, mark it first.

----------------------------------------
The above issues have been resolved:
That's my understanding: The URI is an access address,
1. The "content://" is the ContentProvider application, which can represent a table in a database, or a piece of data. When a specific piece of data is represented, it is often terminated by the ID of the data table: CONTENT://COM.TEST.TAB/1.
2. The expression "file://" refers to the path address of a file
3. Of course there are other formats: "http://", "ftp://" and so on.

So my code in the above should read:
Java code//uri u = Uri.parse ("Content://media/internal/audio/media/rooster Alarm"); Uri u = uri.parse ("content://media/internal/audio/media/81");//"81" is the "_id" field in the datasheet mmediaplayer.setdatasource ( CONTEXT,U);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.