2014-01-07 2 views
0

나는 following tutorial을 통해 작업 한 바와 같이,이 코드를 건너 왔어요 :이있는 데이터의 종류를보고 관심새로운 안드로이드에 콘텐츠 공급자의 이해 소스

public void onClickRetrieveStudents(View view) { 
     // Retrieve student records 
     String URL = "content://com.example.provider.College/students"; 

, 그래서 가려고 노력 데이터를 보려면 웹 사이트 http://com.example.provider.College/students으로 보내십시오. 그러나 오류가 발생했습니다. 따라서 제 질문은,이 URL이 XML 문서 일종인가요? 이 데이터의 형식은 정확히 무엇입니까 ... 어떻게 볼 수 있습니까?

+0

URL이 맞으면 브라우저에서 열리지 않습니다. 나는 네가 혼란 스럽다고 생각한다. – Raghunandan

+0

위 URL은 WorldWide 웹에서 사용하지 않는 콘텐츠 제공 업체 (Android LOCAL) 용 URL입니다. 서버에서 코드를로드/풀하려는 경우 네트워킹 솔루션이 필요합니다. ContentProviders는 그렇지 않습니다. –

+0

이 질문에 URI와 URL이 혼재되어 있다고 생각합니다. – Magnus

답변

0

사실이 아니며 웹 URL이 아닙니다. 이것은 가상의 ContentURI의 예입니다.

예를 들어, 당신은 너무처럼 UserDictionary를 참조 할 수 - 당신은 또한 create 자신의 수도

// Queries the user dictionary and returns results 
mCursor = getContentResolver().query(
    UserDictionary.Words.CONTENT_URI, // The content URI of the words table 
    mProjection,      // The columns to return for each row 
    mSelectionClause     // Selection criteria 
    mSelectionArgs,      // Selection criteria 
    mSortOrder);      // The sort order for the returned rows 

합니다.

+0

실제 ContentURI – user3166666

+0

의 예를 보여 주시겠습니까? 아니면 더 나은 방법으로 내 콘텐츠를 만들 수 있습니까? 나는 그것을 업로드 할 수있는 서버를 가지고있다. – user3166666

+0

그들은 전화로 살고 마지막 편집에서 [link] (http://developer.android.com/guide/topics/providers/content-provider-creating.html)를 추가했습니다. –

1

나는 다음과 같은 documenation 당신이 익숙해 추천 할 것입니다 :

정보 제공자 :

http://developer.android.com/guide/topics/providers/content-providers.html

을 기본적으로 당신이 컨텐트 리졸버에 "URL"은 (아마도 당신이 somethign 같은 일을하고 있다는 통과 할 때 이) :

// Queries the user dictionary and returns results 
    mCursor = getContentResolver().query(
    UserDictionary.Words.CONTENT_URI, // The content URI of the words table 
    mProjection,      // The columns to return for each row 
    mSelectionClause     // Selection criteria 
    mSelectionArgs,      // Selection criteria 
    mSortOrder);      // The sort order for the returned rows 

당신은 안드로이드가 ContentProvider로 그 URL을 해결하도록 요청할 것입니다. h는 해당 URL을 처리하도록 설정됩니다. URL은 "가상"이 아닙니다. 로컬 객체와 프로세스는 ContentProvider 메커니즘을 사용하여 다른 응용 프로그램에서 데이터를 저장하고 사용할 수있게 해주는 응용 프로그램에 의해 정의되고 존재하는 로컬 객체 및 프로세스입니다.

URL의 목표 (이 경우 URI로 변환 됨)는 원하는 ContentProvider와 원하는 내용을 지정하는 것입니다.
이 코드는 당신의 튜토리얼입니다 :

ContentProviders은 일반적으로

편집이 .. 데이터베이스를 관리하는 등 액세스 위반을 최소화하면서 다른 응용 프로그램에서 사용할 수있는 정보를 확인하려면 응용 프로그램에서 사용된다. 추가 의견을 참조하십시오 코멘트에

/// this url points to the content provider. 
    //The content provider uses it to 
///reference a specific database which it has knowledge of 
//This URI doesn't represent an 
//actual FILE on your system, rather it represents a way for you to tell the content //provider what DATABASE to access and what you want from it. 
    String URL = "content://com.example.provider.College/students"; 
      // This line converts yoru "URL" into a URI 
      Uri students = Uri.parse(URL); 
      /// This call returns a Cursor - a cursor is a object type which contains the results of your QUERY in an order manner. IN this case it is a set of rows, each of which has a number of columns coresponding to your query and database, which can be iterated over to pull information from the DB.. 



    /// managedQuery takes, as an argument, the URI conversion of the URL - this is 
// where you are actually calling to the contentprovider, asking it to do a query on the 
// databse for some information 
     Cursor c = managedQuery(students, null, null, null, "name"); 

// This line moves to the first ROW in the cursor 
      if (c.moveToFirst()) { 
      // this does somethign as long as the while loop conditional is true. 
      do{ 
    // This line creates a pop up toast message with the information stored in the columns of the row you the cursor is currently on. 
       Toast.makeText(this, 
       c.getString(c.getColumnIndex(StudentsProvider._ID)) + 
       ", " + c.getString(c.getColumnIndex(StudentsProvider.NAME)) + 
       ", " + c.getString(c.getColumnIndex(StudentsProvider.GRADE)), 
       Toast.LENGTH_SHORT).show(); 
      } while (c.moveToNext()); 
      } 

귀하의 질문이었다 :

는 "나는이 필요로하는 모든이 파일의 예입니다 : 문자열 URL ="내용 : //com.example.provider.College/students ";, 데이터 모양은 무엇입니까?"

이 답변은 사용자가 휴대 전화에 Sqlite 데이터베이스를 가지고 있다는 것입니다. 일반적으로 응용 프로그램 및/또는 컨텐트 공급자에 의해 생성됩니다 (이 경우에는 확실히). 액세스. 또한 콘텐츠 확인자가이 URI와 다른 정보를 받아들이고 커서를 돌려 줄 것이라고 알고 있습니다.

이 질문은 커서가 무엇인지 설명합니다.

use of cursor in android

자습서를 읽는다면 충분히이 코드 ::

public class StudentsProvider extends ContentProvider { 

    static final String PROVIDER_NAME = "com.example.provider.College"; 
    static final String URL = "content://" + PROVIDER_NAME + "/students"; 
    static final Uri CONTENT_URI = Uri.parse(URL); 

    static final String _ID = "_id"; 
    static final String NAME = "name"; 
    static final String GRADE = "grade"; 

또한 발견 할 것이다, 당신의 튜토리얼의 매니페스트에서 찾을 수 있습니다 :입니다

<provider android:name="StudentsProvider" 
     android:authorities="com.example.provider.College"> 
    </provider> 

을 해당 URI에 대한 ContentProvider의 등록.

귀하의 URL과 "PROVIDER_NAME"및 "URL"의 유사점이 있습니다. 이것은 ContentProvider가이 값을 사용하여 안드로이드 시스템에 대한이 partiuclar URI의 리졸버로 자신을 식별하기 때문입니다.

자습서에 설명 된대로 파일을 만들어 샘플 앱을 작동 시키면 더 명확하게 이해할 수 있습니다.

+0

어떻게 이런 종류의 튜토리얼을 할 수 있도록 내 자신의 URL을 만들 수 있습니까? 내 서버에 업로드 할 수 있습니다. 난 그냥 이런 종류의 URL에 대한 데이터 형식을 볼 필요가 – user3166666

+0

웹 서버에서 /로 데이터를로드하려는거야? 그렇다면 ContentProviders가 당신이 찾고있는 것이 아닙니다. 네트워킹 솔루션이 필요합니다. 다음을 참조하십시오. http://developer.android.com/guide/topics/providers/content-provider-creating.html Databaase를 로컬로 만들려는 경우. –

+0

이 파일의 예는 다음과 같습니다. String URL = "content : //com.example.provider.College/students"; , 데이터는 어떻게 생겼을까요? – user3166666

관련 문제