简体   繁体   中英

How to implement app indexing with library project?

I'm trying to implement app indexing for one of my apps, but I'm not quite sure what I should return as the appUri for the app indexing Action .

Let's say I have a the package name com.example.myapp and the webUri http://example.com/some/path .

As I understand it, the appUri would normally be com.example.myapp/http/example.com/some/path in this case, correct?

Now enter the library project that my app uses, and where the indexed activity exists. Let's call the library project com.example.mylibrary and the indexed activity MyActivity .

If I want to start the activity using adb, I would use

adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/some/path" com.example.myapp/com.example.mylibrary.MyActivity

So, my question is - what should the appUri for the app indexing Action be in this case? Is it affected at all by the fact that the activity is within the library project?

In general you can build Action by Action.Builder provided by library. As uri you need to provide related URI. So if you want to index View Action you should provide URI of product, that was viewed.

Uri.Builder builder = new Uri.Builder();
    String uriStr = builder
        .scheme("http")
        .authority("example.com")
        .appendPath("some/path").build().toString();

    Action action = new Action.Builder(Action.Builder.VIEW_ACTION)
        .setObject("productName", uriStr)
        .build();


For more details you can look at logging actions docs and their sample app.
To test:

adb shell am start -a android.intent.action.VIEW -d "{URL}" {package name}

where {package name} = com.example.myapp and URL = http://example.com/some/path

At the end, your Activity placed in library should have intent filter which can handle your URI http://example.com/some/path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM