0

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?

Magnus
  • 17,157
  • 19
  • 104
  • 189

1 Answers1

0

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

x90
  • 2,140
  • 15
  • 25
  • Sorry, but your `adb` command doesn't work for me, I get a `Error: Activity not started, unable to resolve Intent`. I believe this is because the activity is inside the library project, which is the reason I'm asking the question in the first place (see the `adb` command in the question - that's working since it references the library project)... – Magnus Mar 28 '17 at 20:31
  • My bad - turns out the quotation marks around the URL had somehow got mangled into those fancy quotation marks (`“ ”`)! For some reason that caused `Error: Activity not started, unable to resolve Intent` when only using the package name, but worked fine when specifying the full package name + activity. Problem solved. – Magnus Mar 29 '17 at 08:28