Home > Net >  Share web article with my Android Studio app
Share web article with my Android Studio app

Time:01-08

I would like to develop an Android app that allows me to share a web article (from the browser on my phone) with my app. So that I can save the link of the article (or if possible even the whole text of the article) in my app. The target is that the user then can just click on the link at a later point in time and reopen the article in the browser again.

Unfortunately, I only find confusing information on the internet and no real concrete example. Can anyone help me, please? :(

CodePudding user response:

I assume that you are looking to create an app to receive a link from a browser, where the user uses a share menu option (or toolbar button or whatever) in the browser.

Generally speaking, to do that, you need to implement an Activity that supports the ACTION_SEND protocol. There are two main pieces to that.

First, you will need to add an <intent-filter> to the <activity> in your manifest, advertising that you support ACTION_SEND for plain text:

      <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
      </intent-filter>

Then, in your activity, you can get the ACTION_SEND Intent and get the URL. Roughly speaking, that would be:

  private fun saveBookmark(intent: Intent) {
    if (Intent.ACTION_SEND == intent.action) {
      val pageUrl = intent.getStringExtra(Intent.EXTRA_STREAM)
        ?: intent.getStringExtra(Intent.EXTRA_TEXT)

      if (pageUrl != null && Uri.parse(pageUrl).scheme!!.startsWith("http")) {
        // TODO something with the URL
      } else {
        // TODO you did not get a URL, so show an error or something
      }
    }
  }

You would call saveBookmark() from two places:

  • onCreate(), passing in the value of getIntent()
  • onNewIntent(), passing in the Intent that you get as a parameter to onNewIntent()

You can learn more about this in the documentation.

CodePudding user response:

What you're looking for is a backend system for your application. You should check Firebase. Use Firebase Authentication for user login, and Firebase Firestore/Realtime Database for syncing the links.

You will obviously need a web-based client to share the links to the app from the browser.

  • Related