Probleme mit Android UriMatcher

In einer Antwort auf eine frühere Frage von mir jemand darauf hingewiesen, dass es einige Verhornungen (for Lack of a better word), die in der Android-Klasse UriMatcher. Kann mir jemand sagen, bekannte Probleme mit UriMatcher? Ich bin der Gestaltung einer Content-Anbieter, setzt auf UriMatcher an meinem Uris korrekt (im Gegensatz zu falsch, nehme ich an). Gibt es workarounds für bekannte Probleme? Oder gibt es eine bessere Strategie für die passende Uris?

Beispiel:

Hier ist der code, der die Einstellung meiner UriMatcher

private static final int MEMBER_COLLECTION_URI = 1;
private static final int MEMBER_SINGLE_URI = 2;
private static final int SUBMATERIAL_COLLECTION_URI = 3;
private static final int SUBMATERIAL_SINGLE_URI = 4;
private static final int JOBNAME_COLLECTION_URI = 5;
private static final int JOBNAME_SINGLE_URI = 6;
private static final int ALL_MEMBERS_URI = 7;
private static final int ALL_SUBMATERIAL_URI = 8;

static
{
        //return the job and fab for anything matching the provided jobName
        //JobNames/jobName
        uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/*/",
                          JOBNAME_SINGLE_URI);
        //return a collection of members
        //jobName/member/attribute/value
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/member/*/*/",
                          MEMBER_COLLECTION_URI);
        //return a single member
        //jobName/member/memberNumber
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/member/*/",
                          MEMBER_SINGLE_URI);
        //return a collection of submaterial
        //jobName/submaterial/attribute/value
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/submaterial/*/*",
                          SUBMATERIAL_COLLECTION_URI);
        //return a single piece of submaterial
        //jobName/submaterial/GUID
        //GUID is the only way to uniquely identify a piece of submaterial    
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/submaterial/*",
                          SUBMATERIAL_SINGLE_URI);
        //Return everything in the member and submaterial tables
        //that has the provided attribute that matches the provided value
        //jobName/attribute/value
        //not currently used
        uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/",
                          JOBNAME_COLLECTION_URI);
        //return all members in a job
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/members/",
                          ALL_MEMBERS_URI);

}

Fügen Sie eine andere Uri:

private static final int MEMBER_COLLECTION_URI = 1;
private static final int MEMBER_SINGLE_URI = 2;
private static final int SUBMATERIAL_COLLECTION_URI = 3;
private static final int SUBMATERIAL_SINGLE_URI = 4;
private static final int JOBNAME_COLLECTION_URI = 5;
private static final int JOBNAME_SINGLE_URI = 6;
private static final int ALL_MEMBERS_URI = 7;
private static final int ALL_SUBMATERIAL_URI = 8;
//ADDITIONAL URI
private static final int REVERSE_URI = 9;

static
{
        //return the job and fab for anything matching the provided jobName
        //JobNames/jobName
        uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/*/",
                          JOBNAME_SINGLE_URI);
        //return a collection of members
        //jobName/member/attribute/value
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/member/*/*/",
                          MEMBER_COLLECTION_URI);
        //return a single member
        //jobName/member/memberNumber
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/member/*/",
                          MEMBER_SINGLE_URI);
        //return a collection of submaterial
        //jobName/submaterial/attribute/value
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/submaterial/*/*",
                          SUBMATERIAL_COLLECTION_URI);
        //return a single piece of submaterial
        //jobName/submaterial/GUID
        //GUID is the only way to uniquely identify a piece of submaterial    
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/submaterial/*",
                          SUBMATERIAL_SINGLE_URI);
        //Return everything in the member and submaterial tables
        //that has the provided attribute that matches the provided value
        //jobName/attribute/value
        //not currently used
        uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/",
                          JOBNAME_COLLECTION_URI);
        //return all members in a job
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/members/",
                          ALL_MEMBERS_URI);
        //ADDITIONAL URI
        uriMatcher.addURI(JobMetaData.AUTHORITY, "*/reverse/*",
                          REVERSE_URI);

}

Und die Letzte Uri wird nicht erkannt mit:
uriMatcher.match(uri)

Auf der vorherigen Frage erwähnt) es wurde empfohlen, dass ich zu bewegen, die beanstandeten Uri an der Spitze der Aufrufe UriMatcher.put(String, int). Das löste das Vorherige problem (und verließ mich mit einem schlechten Geschmack im Mund). Der Versuch, die Lösung mit diesem code Ergebnisse in der aktuellen erste-Uri (JOBNAME_SINGLE_URI) gehen nicht erkannte. Ich bin mir ziemlich sicher, dass das Problem nicht in meinem code (ich habe es geschafft, erstellen Sie eine funktionierende ContentProvider Nutzung von Uris und debug alle Probleme, die mit Ihnen vor in dieser Ausgabe), ist aber eher ein Problem mit der Uri-matching in Android.

UPDATE:

public final static String AUTHORITY = "dsndata.sds2mobile.jobprovider";

Beispiel Uri:

Inhalt://dsndata.sds2mobile.jobprovider/SDS2MobileDemo/reverse/C_1

  • Ich denke, Sie werden das hinzufügen von zusätzlichen Schrägstrich (/) am Ende von jedem Pfad. Versuchen Sie, und sehen, ob es funktioniert.
  • Diese Lösung wurde angeboten, die auf die Vorherige Frage, die ich erwähnt habe. Es hatte keine Wirkung. Plus, ich habe andere Uris mit den trailing '/' erkannt.
  • Auch Sie sollten verwenden Sie # zum Vergleich der Nummern oder ids.
  • Ich bin nicht mit zahlen. Ansonsten würde ich mich.
  • Was ist dein URI, wo JOBNAME_SINGLE_URI geht nicht erkannten?
  • Wenn ich den REVERSE_URI an die Spitze der put-Anweisungen dann JOBNAME_SINGLE_URI geht nicht erkannten, wo er zuvor arbeitete.

InformationsquelleAutor Lunchbox | 2011-02-17
Schreibe einen Kommentar