Detect URL open - java

I have an android app where in some places it may have the URLs (e.g. from push notifications, in some views where text is pulled from BE, etc.). My question is: is there any fast and good way to detect that app opens up a URL and redirect it to the web browser? I want to check the opened URL and in some cases stop app from opening web browser and do my custom action instead. Thanks

Not directly. If you are using Intent Action view and passing like this
ContextCompat.startActivity(
context,
Intent(Intent.ACTION_VIEW, Uri.parse(appLink)),
null
)
You could use a broadcast manager sent it there and from on onReceive method you can call the code to launch web browser from broadcast.
You could perhaps use a WebView and intercept all request calls using this code
mWebView?.setWebViewClient(object : WebViewClient() {
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
LogUtils.d(request?.url)
return super.shouldInterceptRequest(view, request)
}
})

Related

Get data from Chrome Custom Tab request URL in Android

I am trying to implement a PayPal Vault Braintree payment solution. But since it is a "redirect" process via Chrome Custom Tab, I am having trouble finishing the process. This because in Paypal Web version, the "data response" returns in URL to be used. However, on Android I cannot achieve the same result since the Chrome Custom Tab Works in parallel to the application.
The documentation talks about some listeners that are supposed to work automatically and also about some handlers that can be added manually. However, I don't know how to trigger these listeners and I was also unable to implement a "response" in the handlers.
For now I can open the PayPal page and finish the authentication and authorization, but I do now know how to get data from response.
Anyway, any help would be cool.
Thank you.
The function opening the Chorm Custom tab:
public void startBillingAgreement() {
PayPalRequest request = new PayPalRequest()
.localeCode("US")
.billingAgreementDescription("Your agreement description");
PayPal.requestBillingAgreement(getBraintreeFragment(), request);
}
The process guide (they say about the onPaymentMethodNonceCreated function, but i do not know how to)
The listeners guide

codename one local notifications not working on ios

I have added a local notifications so when my app gets a push while opening there is still a popup and a sound.
It's working fine on Android, but on iOS the local notification doesn't appear at all.
The push notifications are working fine on both platforms.
This is my code in the push callback that should trigger the notification (if the app is open):
if(Display.getInstance().getCurrent() != null) {
LocalNotification n = new LocalNotification();
n.setId(value);
n.setAlertBody(value);
n.setAlertTitle({app name});
n.setBadgeNumber(1);
Display.getInstance().scheduleLocalNotification(n, System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE);
}
Local notifications don't fire while the app is open in the foreground. You should use a different mechanism to make a sound while the app is running. Eg Display.vibrate()
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DriverNotification" object:nil userInfo:userInfo];
// [[NSNotificationCenter defaultCenter] postNotificationName:#"UserNotification" object:nil userInfo:userInfo];
NSLog(#"%#",userInfo);
}
Put This Code in Your View Controller
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveNotification:) name:#"DriverNotification" object:nil
];
Did you call registerUserNotificationSettings to register the fact that your app uses local notifications? If you don't do that, your request to post a local notification will be ignored.
See this text from the description of that method:
If your app displays alerts, play sounds, or badges its icon, you must
call this method during your launch cycle to request permission to
alert the user in these ways. (You must also make this request if you
want to set the applicationIconBadgeNumber property directly.)
Typically, you make this request if your app uses local or remote
notifications to alert the user to new information involving your app.
The first time your app launches and calls this method, the system
asks the user whether your app should be allowed to deliver
notifications and stores the response. Thereafter, the system uses the
stored response to determine the actual types of notifications you may
use.
After calling this method, the app calls the
application:didRegisterUserNotificationSettings: method of its app
delegate to report the results. You can use that method to determine
if your request was granted or denied by the user.
It is recommended that you call this method before you schedule any
local notifications or register with the push notification service.
Calling this method with a new user settings object replaces the
previous settings request. Apps that support custom actions must
include all of their supported actions in the notificationSettings
object.
you need to add below code in didFinishLaunchingWithOptions method of AppDelegate.m file for register local notification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
}

Press a button to carry out an async http get request and flash success on current page if successful (http.OK)

I have a button in play framework web app that links to a routes.Application.refresh
I need it to trigger a separate HTTP GET request say,
http://somehost/restful/refresh?id=123
If the GET request results in a success/200 response, then flash a success note onto the current page where the button we pressed lives. How can I do this?
Here is the myapp.controller.Application.java :-
public static Result refresh() {
flash("success", "cache refreshed successfully on somehost");
return GO_HOME ;
}
The flash part is not really that interesting when doing ajax, it is more for full page reload and then showing it in a play template.
Normally you would write a js callback in your ajax logic that will react on a success (or error) and shows the ui-component that you want the user to get as feedback. This can be done in a million ways, one example would be using jquery.

Stop Android Process from Web App

I'm working on an Android app that communicates with a web app and I need help figuring out how to stop a process in the Android app from the web app. I need to allow the user of the web app to simply click a button which will stop a process within the android app. Any ideas on how to do this? Any help would be great. Thanks!
Edit: I'm using JavaScript for my web app.
Actually you can call native Android code from WebView. This means that you can call whatever function you want of your Adnroid app from within your Web app. See this:
Calling native code from within web view:
When creating the web view add javascript interface (basically java class whose methods will be exposed to be called via javascript in the web view).
JavaScriptInterface jsInterface = new JavaScriptInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(jsInterface, "JSInterface");
The definition of the javascript interface class itself (this is examplary class I took from another answer of mine and opens video in native intent)
public class JavaScriptInterface {
private Activity activity;
public JavaScriptInterface(Activity activiy) {
this.activity = activiy;
}
public void startVideo(String videoAddress){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp"); // The Mime type can actually be determined from the file
activity.startActivity(intent);
}
}
Now if yo want to call this code form the html of the page you provide the following method:
<script>
function playVideo(video){
window.JSInterface.startVideo(video);
}
</script>
So you need to add the appropriate method to JSInterface and call the code from within the Web App.

How does the default browser on Android send "SEND" intents?

I'd like to enable a "silent send" from my application-- that is, I'd like to catch the SEND intent in a Service, not an Activity. How does the default Android web browser send that intent? Is it possible to handle it in a Service, or in an Activity that never sets a View?
Is it possible to handle it in a
Service, or in an Activity that never
sets a View?
ACTION_SEND Intents are sent as activity intents (e.g., startActivity()), and so you cannot have a Service receive them. You can have them handled by an Activity that never calls setContentView(), though.

Categories