how to launch app in hidden icon mode at home menu android - java

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.

Related

How do I press HomeButton and app closes, then I want to logout client so if he presses the App Icon again

Like the question been struggling with this for a day now
I tried out onPause, onStart etc but they all seem to fire regularly.
My setup is this I discovered a bug in my App.
If I start App gets directed to login screen Activity!
I have all the login possible, but if I press the Home button on my Android phone.
The Middle one. App closes down... I then go back to the icon and press it.
The app opens and automatically passed login activity.
So I tried multiple ways with the different events firing to redirect back to the login screen but nothing is working correctly.
For example, if I trigger a start activity call in the restart event.
but then login activity is overriding everything even starts again after pushing loginbutton.
I hope this explains a bit but I am open to trying anything at this point.!

Foregound Service start action from MainActivity

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.

Start Activity on Reboot Only

Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android

Is it possible to detect exit of an application?

My android application allows to launch other installed applications from this.This shows some allowed apps. If the user try to launch a disallowed application then show a message and go back to my activity (from where each application launch) using running tasks. My application act as a home launcher.So intent to this activity if the is a blocked application.For eg: It is possible to launch Camera from Gallery in Samsung device.If the camera is not an allowed one shows blocked message and exited to my acivity.But when relaunching Gallery the blocked message shows again beause the top activity(Camera activity) lied in the stack.
But the exiting of these blocked application did not work perfectly.
Is it possible to get close/exit event of an application?
How can i finish an application as whole(By finishing all its applications).
How to launch an application without having any history of previous launch?
Thanks in Advance
Is it possible to get close/exit event of an application?
Yes it is possible inside your LauncherActivity You can override onDestroy this method will be called on application exit.
How can i finish an application as whole(By finishing all its applications)?
I believe you want to stop your all running activities here. This can be achieved in multiple ways.
android.os.Process.killProcess(android.os.Process.myPid());
or
Intent intent = new Intent(getApplicationContext(), YourHomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
This will clear all the activities and will brings the user to the HomeActivity. While calling this you can add a flag in intent and using that value you can finish the HomeActivity also. Use finish() method to finish the activity.
How to launch an application without having any history of previous
launch?
You can use the same above Solution to achieve this. The second one.
Hope this will help.
There is an onTerminate method in application class, but this cannot be used in production environment. See more about this here

How to invoke browser without losing browsing state?

I have written an activity that has 2 image buttons (1 for messaging and another for browser). On click on each will start messaging and browser android activities respectively.
My question is: whenever I start my app and click on any of the buttons say browser button for example, and after it starts the android browser app, and it allows me whatever to browse in this time if I press the home button on android emulator and again if I start my app and select the browser button in my activity as usual the browser get started from the beginning rather than starting form where I left previously.
Should I start a service to call browser activity or should I set some flags while calling android browser activity?
You might try setting the FLAG_ACTIVITY_REORDER_TO_FRONT on your browser intent and see if it's the behavior you're looking for. This way if the browser already exists, it will just reorder the browser activity to the front and not launch a new browser.

Categories