Retrieve content from custom tab in app - android

After searching for hours I have to ask: Is there a way to retreive the content from a chrome custom tab from the hosting activity in android?
My prefered way would be to start Chrome Custom Tabs from my App via StartActivityForResult and react in OnActivityResult. Until now I only managed to receive back the requestCode, but data is always null (and resultCode always canceled).
I've learned it would be possible by setting up a way through deep linking and pushing an intend defined via javascript on a website to a specific app handling exactly that deeplink uri schema (e.g. here: Chrome Devs intents).
But this seem rather complicated for passing a success or failed back to the app after solving a task at the server.
So: Is there a way to put some data to the Chrome Tab passed back as result to the hosting Activity?
BTW: A side question: If I would use deep linking instead, wouldn't this mess up the "proper" lifecycles a bit? App->starts ChromeTab->starts Intent->starts App again?
Any hints are very apreciated!

Related

Custom share modal for sharing into Android app

How do you create a custom modal layout for sharing data into an application? For example, if you are on a page in Chrome and try and share into Facebook, the Facebook share modal pops up and lets you edit the data that gets passed into Facebook. The Android docs only cover the simple use case of launching an activity within the application and passing in the data. However, I don't want to launch the activity; I want this to be a separate modal altogether that just functions as an overlaid form and sends it to a backend much like Facebook's share function.
However, I don't want to launch the activity
Sharing is only done via activities.
I want this to be a separate modal altogether that just functions as an overlaid form and sends it to a backend much like Facebook's share function.
Then create a separate dialog-themed activity that has your ACTION_SEND <intent-filter>. That dialog-themed activity can collect information from the user, then forward that along to whatever inside of your app.

Set default browser from within app

I'm developing an app that we will put on Android tablets on be used by employees in the field. We want to lock down internet access as much as possible to minimize data usage (so that the employees can't go streaming Netflix movies or something and driving up our data usage). As part of that effort, I'd like to have http(s)?:// links open up in a custom activity I made. Now, I can easily do that by registering the activity with an intent filter on the http/https schemas, but I'd prefer not to have the user have to choose between browsers when opening a link, and I don't want my activity to become the default activity for every link (there may be situations in which the user should be using the Android browser).
Is there a way to set up my activity as the http handler...but only for links launched from my app?
Is there a way to set up my activity as the http handler...but only for links launched from my app?
If the links are from your app, just use startActivity() with an Intent identifying your activity, rather than some generic Intent like ACTION_VIEW.
If your issue is that you are displaying the Web content in a WebView and links clicked there lead to the browser, use setWebViewClient() along with a WebViewClient implementation that handles shouldOverrideUrlLoading().

Use login web session from webview to another activities

I develop an android application which makes login to a php openid server by using webview.
My problem is that once closed the activity of this webview, I need to make requests to the server from other enforcement activities that use the session logged from the first activity with the webview.
How can I use from other activities (not webview) the generated session on the server from the first activity (web view)?
thank you very much
Your questions is very general, so at best all I can do is give you a very general response. If you need to do stuff in the background over a long period of time, please checkout the Service class. Also, with any mobile platform it's generally considered better practice to not use stateful web communication (i.e. communication that relies on sessions). Doing so is not very fault tolerant (and trust me, with any mobile platform your communication is going to need to be very fault tolerant). Instead you should look at making your communication RESTful. Here's a great video on developing RESTful applications for android.
I solved my problem as follows:
I left openid login activity, just for that.
I created a new activity with a webview hidden from the user.
Since the activity where I want to perform the operation on the server with the login with openid, step right url as a parameter to the login activity and this in turn if the user was already logged in login or before, passing the same url the activity with hidden webview, which simply executes the instruction and returns to the main activity (shown only a very small period the user).
In this way it works, because since the webview if you can control whether the user is logged or not openid.

Programmatically clear browser cache/history

During my activity I'm sending an intent to the browser in order to display a webpage :
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ww.mywebpage.com");
startActivity(i);
I need to make sure that before sending the intent the browser cache and history are cleared so that the page get loaded from server directly and not from phone.
So far I've found the 2 following but I'm not sure they are used correctly :
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());
Also with that cache is not cleared.
Do you know how to do that ?
First, you are assuming there is only one Web browser for Android. You are mistaken, and will be increasingly mistaken over time. Steel, Dolphin, Opera, etc. are already in production for Android, and Mozilla's Fennec is coming along nicely. This solution will not help you with other browsers.
Second, if a browser is incorrectly caching your data, your problem is probably on the server (i.e., not sending proper cache control headers). I'd try to fix it there, so that it will behave properly across all browsers.
Third, wiping the user's entire history and searches, to satisfy your requirements, is rather unprofessional. How would you like some desktop app wiping out your desktop browser's history and searches?
Fourth, you cannot clear the browser's cache programmatically.
Yes... and if you must assert more control on the client side rather than fixing it at the server, you'll need to display the content with a webview inside your application where you have full control, rather than delegating to the browser (which is a separate application running under a separate user id and separate security context that you can't mess with).

Find out which browsers are installed?

I'm looking for a way to find out which browsers are installed on the Android Smartphone and their package names.
Why do I need it?
Well basically, my App reacts on certain URLs, i.e. http://bit.ly, so when the click such an he will get an choice in which App to open it. So far everything is working as intended.
If the user sets up this app as default for this kind of links, it will always open in this one without further asking the user. So far so good too. But by doing this, he will be completely unable to open this links in his browser.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user has set to be default for http/https scheme for example (as user can change it if there is more than 1 browser installed).
Sending the intend with
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
should't be a problem I think. The problem is, I can't send a standard intent für URLs, because my App would catch it again if set as default by the user.
should't be a problem I think
Hardwiring in the package and class names of code that is not yours is always a problem.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user
has set to be default for http/https scheme for example (as user can change it if there is more than 1
browser installed).
Use PackageManager and queryIntentActivityOptions() to filter your activity out and get a list of other activities that the user can choose from.

Categories

Resources