42945

Need App Indexing enabled sample code part

Question:

I have working on App Indexing feature in my app and following the Google Developers guide. From the <a href="https://developers.google.com/app-indexing/webmasters/appindexingapi" rel="nofollow">guide</a> I have sticking on the following.

// Create App Indexing Link objects AppIndexingLink item1 = new AppIndexingLink(appUri1, webUrl1, this.findViewById(R.id.btn1)); AppIndexingLink item2 = new AppIndexingLink(appUri2, webUrl2, this.findViewById(R.id.btn2));

From the above statements we can notice the parameters.

My Query on this:

<ol><li>In that document they mentioned the web URL is optional. But when I remove that gives compilation error and if I make it empty ("") gives NullPointerException (Not sure the empty causes the NullPointerException )</li> </ol>

2.The btn1 and btn2, where should we get those from? Why we have give them there? . If I give any view from my project yields NullPointerException(This is the situation which makes me not sure on the first one).

If any one have tutorial AND sample codes to enable the App Indexing , kindly provide it. Its may help us.

Answer1:

1-webUrl1 is a object of Uri type you need to parse some url ex use your google play url

2-btn1 and btn2 can be any view the user is viewing example a image view or a text view containign some text

Answer2:

Try this easier way of integrating appindex.

Add intentFilter to any of your activity that going to handle Appindex,

<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" android:host="www.yoursite.com" android:pathPrefix="/" /> </intent-filter>

After that in that oncreate of that activity you can use

Uri data = getIntent().getData();

This data will give the full url that landed to your app.

System.out.println("Data URL: "+data);

And also you can this uri data to get host name.

if(data!=null) { String tmpData = data.toString(); String hostName = data.getHost(); }

Ensure that you have done site verification from webmaster tool before you make the app live.

Recommend

  • Initialization order of values in objects: How to setup cyclic/recursive objects properly?
  • Hashtable getting null for existing key
  • Android FileProvider delete file
  • How to compile unsafe code in MonoDevelop 2.4
  • “Yesod devel” fails with fromJust in devel.hs
  • Can't use openlayers-3 with webpack
  • Aspect advising other aspects
  • Can't get LogCat (Alcatel OneTouch Evolve)
  • Defining variable by logical subseting on time interval in data.table
  • Exception in the iconization of JInternalFrame with DefaultDesktopManager
  • Partial specialization of a class template in derived class affects base class
  • XNU incudes in Kext
  • Fail:(TESTMODE) Transactions of this market type cannot be processed on this system
  • How do I get HTML corresponding to current DOM tree?
  • Jackson Parser: ignore deserializing for type mismatch
  • Custom Tabgroup Appcelerator
  • iOS: Detect app start via notification press
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Initializer list vs. initialization method
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Linq Objects Group By & Sum
  • Why is an OPTIONS request sent to the server?
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Optimizing database types to compact database (SQLite)
  • Change an a tag attribute in JavaScript based on screen width
  • Is there a mandatory requirement to switch app.yaml?
  • Cannot Parse HTML Data Using Android / JSOUP
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Getting Messege Twice Using IMvxMessenger
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • reshape alternating columns in less time and using less memory
  • UserPrincipal.Current returns apppool on IIS
  • How to load view controller without button in storyboard?