Android: onConnectionToInternet - java

I want to know if there any listener, like onClickListener , but for connection to the Internet. I want to start some function, only when there is a new connection to Internet.
Exactly like a Button, that till it is not pressed, it's not start the onClick.
Does someone know something like that?
Thanks in advance!

Check out BROADCAST RECIEVER
What happens is as soon if a change in network ex:Internet, android
fires an intent
You can use this Intent as per your wish to achieve your objective,
like performing some tasks
You can place the Broadcast reciever in your main activity
Don't forget to declare it in manifest
CHECK THIS STACKOVERFLOW POST- IT WILL GIVE YOU THE IDEA ON HOW TO USE
Hope this helps !, comment back if you need any more information

Related

Possible to determine if user has clicked on ANY notification (not just from my app) in real time?

I'm making my first Android app. Is it possible to listen to any commands that is triggered when a user clicks on any notification? I don't need to know which notification that was clicked, just the fact that any notification was clicked on.
Maybe it's possible to listen to FLAG_AUTO_CANCEL or similar.
I'm a beginner, so please excuse me if I'm not clear enough or using the wrong vocabulary.
When a notification is clicked the ContentIntent is executed and that's it, there will not be a Broadcast that a notification has been clicked.
So to answer the question, it's not possible

SearchView voice listener

I would like to know if it is possible to set voice listener on my searchView, like the suggestion listener:
http://developer.android.com/reference/android/support/v7/widget/SearchView.OnSuggestionListener.html
I want to overwrite the default behavior. I don't want to launch another activity. I just want to get the recorded voice as a string and use it.
I read what you ask for, but Why don't you want to use an activity?
Just in case this can help you, you should take a look at these if you havn't till now:
Andriod developers:
http://developer.android.com/guide/topics/search/search-dialog.html#VoiceSearch
Examples:
http://www.codeproject.com/Articles/821839/A-Beginners-Guide-to-Working-With-Speech-and-Audio
http://www.truiton.com/2014/06/android-speech-recognition-without-dialog-custom-activity/
Hope it helps,
yakobom
To show the microphone icon you need to add a search configuration and set it to your SearchView. See this question and my answer here https://stackoverflow.com/a/48527608/114549

Launch the same activity for different buttons with different resource

I am new to android and was starting out by making a list of button.i want when each button click launch a same activity for them with diffrent resource such image and raw file
what is big deal here?
call same intent twice :)
refer how to start new activity here
You can the same activity/intent multiple times, just if you want the code in said activity to do something else you might want give it some extra information by using intent.putInt(<Key>, <Value>); and others

Pressing back button on Calling screen takes user to home page. Any solution?

What i want to do is to allow user to call a number from application. i am using following code for this which is working fine for calling a number. But however when i press back button during call it takes me home page instead of back in previous screen of the application where the calling application was invoked from. please have a look over code and if anybody have solution please help me.
PhoneArguments callArgs = new PhoneArguments(
PhoneArguments.ARG_CALL, "+27 83 111 1234");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, callArgs);
any help would be appreciated. Thanks.
You could use PhoneListener to detect when the call has ended and then try to bring your app to foreground using this:
Application.getApplication().requestForeground();
Not sure if this is going to work though, because I'm not sure if the "application" where the phone listener executes is the phone app itself. I think no, but if it were the case, you could send a global event from the phone listener callback and catch it in your app which in turn could bring itself to foreground.

Preventing tilt from calling onCreate, and time measurement of an activity running.

Hi and thanks in advance for your time and attention.
I actually have 2 questions i'm not too sure about building an android app. Pretty basic stuff I believe:
1) My app is fully on Horizontal mode, like AngryBirds for example. When it starts the user figures out he should hold the phone like that, if he isn't already. And that is setup in the manifest for all the activities and works fine. but is there a way to prevent the physical device tilting to call onCreate again? can i override it's method or whatever? the reason i'm asking, is because i have a few ButtonViews that after you click on them, change their picture. i am using onRetainNonConfigurationInstance() to save the array of those ImageButtons, and i even mark the ones changed with the ImageButton setTag() and getTag() methods, so when onCreate is called because of the device tilt it gets the saved array from getLastNonConfigurationInstance() , but i've been trying to make it work for quite some time now and I just can't get it right. After the device tilt (I'm actually using the emulator so it's Ctrl+F11 but i believe it will happen with a device as well) all of the ImageButtons loose their pictures.. Long story short - are there better ways of doing this that you can recommend or is preventing the tilt from doing anything is possible or better?
2) What is the best way to know how many seconds the user has been on a screen? I tried to use two longs that i get via SystemClock.currentThreadTimeMillis() as follows: get the starting time onCreate, and the ending time on the method i call to move to the second intent just before i startActivity. but I think because they are called from different threads, the endingpoint - startingpoint is not correct. What is the way to insure both of the methods of SystemClock.currentThreadTimeMillis() are called from the same thread, the main thread of the activity that i'm stopwatching? Is there a better way to go around this?
Thanks again.
You are doing the right to handle orientation change. Please refer to this link http://developer.android.com/guide/topics/resources/runtime-changes.html . This will help you to get it working.
Good way would be to count the time between onResume and onPause. OnCreate is not called all the time if you are resuming activity.
1) You can try adding the property android:configChanges="orientation" to your activity in the manifest file. It worked for me when my dynamic Action Bar tabs got messed up upon rotation of the screen.
You need specify orientation in android manifest for each of your activities, it will not call onCreate then. android:screenOrientation look at http://developer.android.com/guide/topics/manifest/activity-element.html
User see and interact with your activity starting since onResume and ends on onPause. Other time it does not guarantee that user actually see and can click on something in the activity. System.getCurrentMillis() is good enough.

Categories

Resources