I am designing an app which needs to know which users are online or offline. Each user can
notify the server if he is online or offline and then I can get that information from the server.
The issue is that is there a standard in android which marks the user as online or offline.
One solution is if the app is running then the user is online, if the app force stopped or not running then the user is offline. So in my app how will I know that the app is stopping?
If the above is not possible or not a good solution then when will my app tell the server that it is going offline.
Thanks in advance.
In Android, there is no hard solid concept of "leaving an application". Apps can be pushed on the stack by pressing home, still alive in the background or pushed away from top by another application. There is no real hook that you can use to say "ok, I am really going down now, I should notify the server".
So, you could take it the other way around : the server grants a bail to a user, for 5mn let's say, and the client app has to renew it. After 5 mn of inactivity, the server can know that a user is going offline.
Off course, the delay will be a trade off between the need of precision/responsiveness you want on the server side and battery usage as this will tend to decrease battery life by constantly notifying the server that the client is still online.
In Android When application is create onCreate() method of Application class is calls when application is force closed onTerminate() method is calls.
If you want to do something when application is create and terminate you need to create your custom application class by extending Application class.
1) Create your own application class like this
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// When application creates
}
#Override
public void onTerminate() {
super.onTerminate();
// calls when application force closed.
}
}
2) In your manifest.xml
<application
android:name="com.yourpackagename.MyApplication"
android:allowTaskReparenting="true"
android:debuggable="true"
android:icon="#drawable/ijoomer_luncher_icon"
android:label="#string/app_name"
android:theme="#style/ijoomer_theme" >
Related
I have written a foreground service in my app and I am doing some API operation every 5 minutes once. My app is mainly used for location tracking and it always needs location permission. If user disable the location for my app by any chance then I just want to create a local notification from my service. My app users mostly don't bring my app to foreground. So I want to check whether the location permission is enabled or not. If not then I just want to show a notification which tells the user that the app needs location permission. Now I just manually went to android settings and disabled the location permission for my app. I have two services running in my app. Suddenly both stopped working. I just want to know the reason why it stopped? Will it be stopped always until I enable the permission? What can I do to intimate my user to enable the permission? As my app always runs in background, I want to handle it in service. Please give your opinion to solve my issue.
NullPointerException: Attempt to read from field'LanguageInitBean$Data LanguageInitBean.data' on a null object reference
When I change the storage permission, I can't read the data stored in memory
Ask for help
public static class LanguageInitCache{
public static LanguageInitBean languageInitBean;
}
private void startToNext(String response) {
languageInitBean = GsonUtils.json2Bean(response, LanguageInitBean.class);
}
This is primarily for my Work place so having an app running all the time is not an issue.
The question How do i attach a hook to activate the App or background process when a call is made, and can it retrieve the phone number?
All the App has to do is send a request with the phone number to a server in-house
The reason for the question:
I am toying with the idea of creating a Support Service module which can give the Service worker a better grasp of the problem at hand.
Consider this:
Customer calls the company's support line
Service worker picks up phone
The computer looks up the Customers phone number on the Company's database and gives the Service Worker every detail they have on the customer ( Issues created, Website, Basic Info )
The biggest problem i can see is how do i Catch the number coming from the phone?
Looking up a customer via their phone number is not the issue.
Alternatively the Service worker will have to manually enter the phone number, but would be a nice feature to do it automatically.
Yes, You will need a BroadcastReceiver and have to override
#Override
protected void onIncomingCallReceived(Context ctx, String number, Date start)
{
//
}
Also insert permissions in Manifest.xml . If you want compatibility over oreo use runtime permissions for those permissions
Android API level 24 introduces a new Service called the CallScreeningService. The documentation says that the service can by implemented by the default dialer to screen incoming calls. I would like to implement this service in my own app, preferably without creating an entire dialer app, but a simple naive implementation seems to be ignored by the OS when an incoming call happens.
AndroidManifest.xml snippet:
<service android:name="com.example.callbouncer.CallService" android:permission="android.permission.BIND_SCREENING_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallScreeningService"/>
</intent-filter>
</service>
CallService.java:
// imports...
public class CallService extends CallScreeningService {
#Override
public void onScreenCall(Call.Details callDetails) {
CallResponse.Builder response = new CallResponse.Builder();
Log.e("CallBouncer", "Call screening service triggered");
respondToCall(callDetails, response.build() );
}
}
There are no errors while building or installing this program, but the screening doesn't seem to be taking place. Have I done something wrong (like the manifest or missing implementations/overrides in the service) or is it just not possible? If it's not possible in a small app like this, will it be possible if I implement an entire dialing app and set it as the default dialer? Finally, if that's the case, is there anything preventing me from just forking the dialer out of the AOSP and adding my features to it?
As of Android 10 (API 29+), you can have a CallScreeningService without the requirement of also implementing an entire dialer app. Until Android 10, only the default dialer app's call CallScreeningService would be invoked.
https://developer.android.com/about/versions/10/features#call-screening
Don't get too excited though, because it's very buggy and does not work as the documentation says it does:
CallScreeningService#onScreenCall is called for known contacts
CallScreeningService#setSkipCallLog doesn't show blocked calls in the call log
My workaround for getting called for known contacts was to ask the user for contact access and check if the incoming caller was in the user's contacts. There is no workaround for the other issues at the moment.
I made a very basic screening app that declines all calls from numbers not in the user's contacts you can use an an example if you like: https://github.com/joshfriend/gofccyourself
Looking at the docs you linked to:
This service can be implemented by the default dialer (see
getDefaultDialerPackage()) to allow or disallow incoming calls before
they are shown to a user.
Don't think you can do this in a separate app (at least with the current interface: I'd expect in the not too distant feature it will be exposed).
Here is the scenario:
Automatic user is enabled via ParseUser.enableAutomaticUser()
I create an object, say a Todo from Offline Todo tutorial (https://github.com/ParsePlatform/OfflineTodos) and pin it:
Todo todo = new Todo();
todo.setUuidString();
todo.setTitle("test");
todo.pinInBackground();
It works fine for the first time
Now close the app (not just send it to background, close it using Recent Apps button and swipe it off the screen)
Run the app again. Here the exact same code above throws this exception:
cannot setReadAccess for a user with null id
Even though a workaround might be to sign-up the automatic user at some point before closing the app that's hardly the point of automatic users which are supposed to work offline plus there is no guarantee that the app won't be closed before our during sign-up process.
Saving the user to get an id is not an option too: not only its an online operation, you are not supposed to call save() on a user. According to documentations it should be signup() instead.
Even pinning the current user before creating other object didn't solve the problem.
Not sure if you found a solution on your own yet for this, but I think this should work: At app start-up, when you enable automatic user creation:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// ...
if (ParseUser.getCurrentUser()==null) {
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground();
}
// ...
}
}
This will (a) ensure that you always have a current user, and (b) if it is an anonymous user that user will persist through application restarts.
Note 1: saveInBackground() won't actually save the user to the server because the user does not have a username/password, but will persist the user.
Note 2: I haven't tested this fully but it should fix your situation.
I'm developing android application for CAR usage and I need that in phone or tablet the driver can only run and use this application: No calling or running other app. Is that possible? If it is not, is there any way to restrict the user for example uninstallaing other apps and disabling the installation system and disabling the calling system?
Thanks in Advance,
I have done a similar app like this, which is in fact an in-cab entertainment system. I have also written a blog post about it, you can check it out here: http://arnab.ch/blog/2012/01/android-auto-updating-homescreen-application/.
This is a complex application and let me list out the relevant items for you:
Your app should be a HomeScreen application (search google for how to create HomeScreen app for Android)
It seems clear that you would have some control over the device, so you can ensure that no additional applications are installed.
The homescreen can be dynamically enabled/disabled, check out KytePhone app to see what I meant. In short you would need some password to exit your HomeScreen app.
If you want to silently uninstall/install any application, then you'd need root access, or you'd have to have a custom Android build where your app will have System privilege (might not be what you're looking for).
I hope I am able to give you some direction, if anything is not clear then let me know.
You can use Accessibility service to solve this issue and you need to check granted application packages inside onAccessibilityEvent method.
import android.accessibilityservice.AccessibilityService;
public class MyAccessibilityService extends AccessibilityService {
...
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
#Override
public void onInterrupt() {
}
...
}
please follow the link: https://developer.android.com/training/accessibility/service.html