开发者

Android: How can I save something in the browser that all apps can access?

开发者 https://www.devze.com 2023-03-30 11:03 出处:网络
Basic Desired Functionality When a user on an android phone visits the URL http://www.example.com?key=asdf I would like the value asdf to be saved in a way that any app on the phone can access it at

Basic Desired Functionality

When a user on an android phone visits the URL http://www.example.com?key=asdf I would like the value asdf to be saved in a way that any app on the phone can access it at a later point.

The End Goal

The goal is a simple way to invite your friends into the app by directing them to a URL. The URL has a link to download my app from the market, so the only thing required to accept the invite is visiting that URL and clicking on a single link. Once you've installed the app, it can then grab the value asdf and connect you with whoever invited you.

Things I've Tried

My original thought was using something like localStorage or cookies, but it seems unlikely a solution involving either of those exists due to security concerns.

The best solution I've come up with so far is using the com.android.browser.permission.READ_HISTORY_BOOKMARKS permission to read through the user's history in search of URL's from my domain. This is a pretty good solution, but it doe开发者_开发问答s not work for other browsers like mobile Firefox. In addition, it requires a shady permission, which I would like to avoid if possible.


To achieve your actual goal you can use the same method that Google Analytics uses. The basic idea is that you you use a URL pointed at the app store with a specifically formatted referrer value that gets passed on to the app. Though the format of this string is supposed to be able to be anything, there have been reports of problems if you don't follow the actual Google Analytics format.

example:

http://market.android.com/details?id=com.example.myapp&referrer=utm_source%3Dfriend%26utm_medium%3Dinvite%26utm_content%3Dasdf%26utm_campaign%3Dinvite

More documentation specific to analytics can be found at Android Google Analytics

You then will need to implement a broadcast receiver for the type com.android.vending.INSTALL_REFERRER

In your manifest it will look like:

<!-- Used for install referrer tracking -->
<receiver android:name=".MyReceiverClass" android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

See Android docs for details on implementing a BroadcastReceiver.

This approach requires that the friend download the app using the Google Marketplace (by clicking on the generated URL) on the device, as it is the MarketPlace app that takes the referrer data and passes it on to the app.

NOTE: While the approach should work there may be problems with the current MarketPlace app that prevent this from working. see bug: http://code.google.com/p/android/issues/detail?id=19247


Sorry, no there is no supported way to do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号