I am working on an Android fall detection application. When user falls, alarm with timer turns on and if user not clik cancel within 15s, app send SMS to contact. Everything works fine when app is open but I don't know how my foreground service should work. Is it possible to make foreground service work like that- after fall detected foreground service open application and run timer from Main Activity?
Code from foreground service opening MainActivity:
Intent myIntent= new Intent(this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
There are two obstacles to your use case:
Firstly, starting from Android 10, there are new restrictions on starting an activity when your app is in the background (and as it's written on the android developer page, even with a foreground service, your app will be considered in the background if no activities are in foreground). So you won't be able to "pop" a view to the user, except if you target a version < 29 (but it's not very recommended).
Secondly, since the beginning of 2019, the Google Play Developer Policy has been updated and you cannot use anymore the SEND_SMS permission, unless if you can justify in the publish console that your app is an SMS handler and you will need the user to register it as the default one. So you won't be able to send an automatic text message directly.
You can try to change the notification message to alert the user and try to have him click on the notification to open an activity.
Related
I am developing a custom dailer App incoming call screen but my problem is that when the app is in foreground, on incoming call the broadcast receiver is called and displays the custom screen but when the app is in the background or not in running state then the broadcast receiver is not called.
How to resolve this?
And Also Getting this Log
ConnectionTracker: Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lt#3e5af9d
On some devices (notably low-end and Chinese manufacture) apps are not permitted to perform background activities if they are not in a list of "protected apps". This is done to save battery life. If your device does this, it will not launch a BroadcastReceiver if the app is not already running. To fix this you will need to manually add your app to the list of "protected apps" or "apps allowed to perform background activities". There is a setting in the Android settings for the user to maintain this list of apps. It is usually in the "Security" or "Power management" settings somewhere.
I am trying to create a locker application to show pin view when the user enters to defended application. I created a service that runs and tracks the current foreground application. However, on devices with android version 10 activity is not starting from my service. I know that from android 10 there are restrictions to start an activity from the background, however, there are exceptions either. The activity can start from the background when the application is in the foreground, but it won't help in my case. So the question is how can I start the activity from service to show pin view?
P.s: I tried it with window manager but again in higher android versions there is an annoying notification that can open settings do dismiss overlay permission. Also, I saw a working "app locker" application in the play store, so I believe there is a way.
From android 10 foreground service will work only if u start the service while the app is in foreground. If your app is in background you will need background location permission which has to be requested separate after you gain permission for coarse and fine location. Also if your app is in testing mode and not in Play Store and u update your device to android 10 a fresh install of the app is needed.
There is no point in using a foreground service if u want to start that service from background. Just get background location and stop using foreground service.
I have app that after installtion need to be hidden in home menu.
the app is for push notifications only.
I read this but android.intent.action.BOOT_COMPLETED not work.
there I read also Think Twice Code Once answer.
so currently I am searching about way to interact with user at least once after installation without activity or with activity in the way that app icon not appear in home menu. or change reciver or service state immediately after installtion without user interaction
any idea?
thanks!
The app needs to be run manually at least once by the user, otherwise the app will remain in the "stopped state" and you will not receive any broadcast Intents. You will need to have an Activity and that Activity will need to have an entry in the manifest with ACTION=MAIN and CATEGORY=LAUNCHER. What you could do is disable the Activity programmatically after it is launched the first time. This would prevent the Activity from being shown on the HOME screen. Here's an example:
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(this, my.packagename.MainActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
NOTE: If you do this, and the user "force stops" your app (Android settings->Apps->YourApp->Force Stop) then there will be no way to restart your app other than uninstalling and reinstalling it.
I have simple app for show pageView with text, I want to notify user at specific time every day to open my app at specific page.
So I test my App by Marshmallow device, I am using alarmManager for this task, but once I close App from main screen notification stop showing.
I used Broadcast Receiver with remote process android:process=":remote" but Alarm not work also I used service also it killed with closing App.
So what is right sequence to achieve this job?
You don't need to use Service. AlarmManager and a BroadcastReceiver to restart alarm service on device boot.
Check this example:
http://stacktips.com/tutorials/android/repeat-alarm-example-in-android
When I was making alarm clock app for me Service with WAKE_LOCK was waking up the phone when it was blocked or the app was killed by user.
This class(with some notification displayed) is preventing app from being killed :
https://github.com/mrkostua/SmartAlarm/blob/master/app/src/main/java/com/mrkostua/mathalarm/alarms/mathAlarm/services/WakeLockService.kt
So after scheduled intent can be send to BroadcastReceiver.
I have an app that has the possibility to log in using a Mifare classic 1K nfc chip. Our customers use another app (nedap) that has the same functionality, but with a different card (same type though). If both apps are open and my app is in the foreground they can log in using our nfc tag. However, when the other app is in the foreground and they try to log in using the other nfc chip, that app refuses to log in (it's just stuck in the login screen without error). If only one app is open there are no problems at all.
Is this my fault or is it an error in the other app? If it is my fault, how can I make sure I don't screw with other apps when implementing nfc functionality?
If an app is launched using the foreground dispatch system, only this app handles the NFC traffic:
The foreground dispatch system allows an activity to intercept an intent and claim priority over other activities that handle the same intent.
When your app goes into background you have to disable it:
Also, activities must call disableForegroundDispatch(Activity) before the completion of their onPause() callback to disable foreground dispatch after it has been enabled.