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

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.

Related

Detect URL open

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)
}
})

Receive URL intent in Splash Screen and load the URL in WebView

I'm having a slightly different purpose, but, I think I'm putting it wrong as no one from multiple forums is able to answer it. The original question is here: Pass URL data from AppLink to WebView
Basically, suppose I'm creating a web browser app with a splash screen and I want to accept the URL intents from other apps, receive them in my splash screen, pass them on to my WebView activity and load it there, how can I do that?
For example, if a user has my app installed, and he/she taps https://www.google.com/ as a link in some app, how can I load the URL in my app after showing my splash screen? I think, the intent receiver will be in the splash screen activity, and the WebView is in another activity. So, basically, I want to receive the URL in my splash screen activity and then, pass it on to my WebView. How to achieve this?
I think what youre trying to do is to recieve data from other apps
That way, you can recieve data in a Splash Screen Activity and then show it in a Web View Activity
You can do this through putExtra method.
You can use intents, which are messages sent between activities. In an intent you can put all sort of data, String, int, etc.
In your case, in Splash Screen(say SplashActivity), before going to next activity(say MainActivity), you need to store a String message this way :
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("message", message);
startActivity(intent);
In MainActivity, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Then you can use message variable as url.:
Hope this helps !

Only calling the OnDestroy() of the mainActivity

I am building an app that allows you to send files to other apps through a server. The thing is that when one of them closes the app by swiping it off, i want to send a disconnect message to the server.
The problem is that imagine that on the stack i have activities A (MainActivity) , B , C and D. If I am in the activity D and I swipe the app off (turn off the app), it will call the OnDestroy() method from the MainActivity. From the MainActivity, i can't send that disconnect message, so my question is why isn't the onDestroy() from the other activities called ?
PS: I could send the disconnect message from the MainActivity, but what if the person didn't reach the server part of the app? What if the person didn't try the part of the app that lets them send and receive files ? I would be sending a disconnect message for something that doesn't even exist.
Or would there be any way where I could check, from within the MainActivity, if the activity D exists ?

android - resuming from last visited page in my app

I have login page (activity) which is my first activity (landing page) of the app.
Only after user gives correct username and password, the app allow you go to other pages to work with.
Now my question is, now the user is at the fourth page and he is working on it, And he minimize the app and use other app like messaging etc..
so when he come back to click my app icon again, my app starts from the first landing page, which is the login page,
how can I make my app to resume from the fourth page?
Android 4.4.4, Kit Kat, Samsung
Regards,
Nay TK
Add this in android manifest of loginActivity,
android:launchMode="singleTask"
more on android:launchMode
An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:
"standard"
"singleTop"
"singleTask"
"singleInstance"
The system creates the activity at the root of a new task and routes
the intent to it. However, if an instance of the activity already
exists, the system routes the intent to existing instance through a
call to its onNewIntent() method, rather than creating a new one.
go through official link for more detail
You can make your fourth activity as your launch activity.
In the Resume of your Activity, you check if the user is logged in. If not, you start your Login activity.

Android c2dm service

Trying to implement google C2DM service.
registrationIntent.putExtra("app", PendingIntent.getBroadcast(context,0,new Intent(), 0));
registrationIntent.putExtra("sender","example#gmail.com");
context.startService(registrationIntent);
Almost every tutorial features this line of code. Is this a service that I must code? or does Android know how to handle this type of Intent. I am calling this method from a helper class with the default constructor. I pass the current Context to the this above method to create the registration Intent. Anyone have some insight on how this works or where my program will go?
No, you don't have to write a service. You need to send an intent to a Google's service. You've omitted the first line, where the intent is created, and that contains the service name. It's something like this typically:
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
The line com.google.android.c2dm.intent.REGISTER identifies the Google's service.
Now, you still have to write the broadcast receiver that'll receive the registration result (either an ID or error). And a receiver to receive the actual C2DM messages.
You left out the most interesting piece of code
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
Is this a service that I must code? or does Android know how to handle this type of Intent.
Note that the intent is in the com.google.android.c2dm domain. The Android C2DM implementation on the device knows how to handle this intent and you will be starting its own service to process it.

Categories