I am implementing application indexing, and I think I am missing something, but I don’t know what.
Following the guide , I added my filter applications to the application and implemented what I needed in my work.
my application package is com.towers.hotelsclick and its related website (where I have not yet added the link meta tag as I am just testing) www.hotelsclick.com
I saw the following intent filter example in the manual
<activity android:name="com.example.android.PetstoreActivity" android:label="@string/title_petstore"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:scheme="https" /> <data android:host="www.examplepetstore.com" /> </intent-filter> </activity>
so I wrote mine like this:
<activity android:name=".ActivityForAppIndexing" android:label="@string/title_activity" android:screenOrientation="portrait" > <intent-filter android:label="@string/app_name"> <data android:scheme="android-app" android:host="com.package.myappname" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" android:host="www.mywebsite.com" /> <data android:scheme="https" android:host="www.mywebsite.com" /> </intent-filter> </activity>
In addition, I wrote a content provider for URI analysis.
<provider android:name=".contentproviders.HotelDetailsContentProvider" android:authorities="com.towers.hotelsclick" > </provider>
which should display the URI as follows:
private static final String BASE_PATH = "https"; private static final String AUTHORITY = "com.towers.hotelsclick"; public static final Uri CONTENT_URI = Uri.parse("android-app://" + AUTHORITY + "/" + BASE_PATH);
I am testing the implementation through the command line using the following adb command:
adb shell am start -a android.intent.action.VIEW -d "https://hotelsclick.com?hotel_id=135738" com.towers.hotelsclick
and it works. The application automatically opens with the correct action and the correct parameters. When the application runs the onNewIntent method, it is called:
protected void onNewIntent(Intent intent) { String action = intent.getAction(); String data = intent.getDataString(); if (Intent.ACTION_VIEW.equals(action) && data != null) { String recipeId = data.substring(data.lastIndexOf("/") + 1); Uri contentUri = HotelDetailsContentProvider.CONTENT_URI.buildUpon() .appendPath(recipeId).build(); bundle = new Bundle(); bundle.putString("pictureUrl", "");
(I got this, of course, from examples of why he talks about recipes, not about hotels)
But I wonder: what should I do? Get data with intent using
getIntent().getData().getQuery()
or use ContentProvider and get them from a URI?
In addition, I’d like to test the Google Search console and the “View as Google” feature if everything is okay. I downloaded my APK and saw that the URI was requested.
Now, in the "testing your application" section of the documentation, I saw that links such as http://hotelsclick.com?hotel_id=135738 are called "deep links", while those that look like android-app: // com.towers.hotelsclick / https / hotelsclick.com? hotel_id = 135738, called "URI", Am I right?
The View as Google function requests a URI, but I don’t know how to create it. In addition, I am interested in how this URI is passed to the application, and I'm sure that I am very confused about all the URIs / deepLink and cannot find relief in the documentation.
Where and when should I use a URI? Where and when should I use deepLink? I assume that since I'm going to put the rel = URI link on my web pages, the application will be called in indexing the application using the URI, not the page URL. But if that is the case ... why does the adb shell run the -a android.intent.action.VIEW -d command, used for testing with a URL and not a URI? Should my application receive and process URIs or URLs? And How?
I thought I understood something about indexing applications, but today I am starting to think that everything has been wrong since I started. That's why I ask you for help in answering the above questions, and perhaps shed some light on this whole URL / URI / intent-filter / ContentProvider mess.
Thanks everyone