My Final project requires that app must be hidden,and never opened again unless entering some code in phone dialer (ex: *123#) can you help me guys to do that task?
This is a bit tricky and it has its up and downs, but what you need to do basically is:
On app install, you need to programmatically disable the app Icon so you cannot open it manually.
Have a BroadcastReceiver registered with the PROCESS_OUTGOING_CALLS intent filter (don't forget to set the uses-permissions).
In the receiver, listen for every dialed number and when it matches yours you need to activate the App Icon again and then you start the activity with possibly extra data to handle it later.
After processing the data in your activity remember to deactivate the icon again.
To programmatically disable the icon use:
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
packageManager.setComponentEnabledSetting(
componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
);
To enable it:
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context, MainActivity.class);
packageManager.setComponentEnabledSetting(
componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
);
In your receiver to get the dialed number you need to use:
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
// Validate and start your activity here
// To start an activity from a receiver you need to use the flag FLAG_ACTIVITY_NEW_TASK in your intent
}
Note: After hiding the icon programmatically you might want to finish() the activity so it closes automatically at first run.
P.S I have a working sample of this, so rest assured as I have tested it actually works, sadly I cannot spoon feed you in your final project. Don't hesitate to ask anything tho. Good luck
There is no such functionality in Android. You may be able to do it with a custom home screen, but there is no "hide this app" functionality in the default launcher.
Related
I ran into the following issue: I have an app I want my user to be able to select it as the launcher app. So far, no issues there.
Clearing said selection programmatically also isnt an issue here. Where my issue occurs is the following:
When I my custom launcher programmatically I want to go back to default launcher app, e.g. the default on a samsung galaxy. clearing the launch settings over clearPackagePrefferedActivities clears all of it but once i press the home button I get the dialog to select a default launcher again.
Is there anyway to revert back programmatically to the default launcher?
The user always needs to confirm a change in the default settings. You can always trigger the "default launcher" dialog by
PackageManager pm = getPackageManager();
ComponentName cm = new ComponentName(this, FakeLauncherActivity.class);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Where FakeLauncherActivity is just another Activity in your app with the intent-filter HOME/MAIN/DEFAULT (without LAUNCHER).
If you want to know the default system launcher you could query the intents answering the LAUNCHER Intent, but if the user has another Launcher installed, you will not know which one is the default system launcher.
Even if this is not a complete solution for your question, I hope it helps you in a useful direction.
Is it possible to create an app without any activities? Without a launcher icon and without the "open" button on Play Store? Like this one https://my.pcloud.com/publink/show?code=XZUi3I7Z6yNkHyuBISL5XynlYYI8SjEJcoMk
I only need it to create a background service.
I've done some research and I haven't found anything about this. If you could just point me in a direction (or tell me it's not possible) it would be great!
Cheers!
You said you didn't want to use a translucent Activity, but that seems to be the best way to do this:
1- In your Manifest, set the Activity theme to Theme.Translucent.NoTitleBar.
2- Don't bother with a layout for your Activity, and don't call setContentView().
3- In your Activity's onCreate(), start your Service with startService().
4- Exit the Activity with finish() once you've started the Service.
In other words, your Activity doesn't have to be visible; it can simply make sure your Service is running and then exit, which sounds like what you want.
how to hide luncher icon :
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Hide open button couldn't be done , because we are talking about an application and not a google library
how to unhide icon :
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
IMPORTANT: It's somehow tricky if you need to do something with main activity in your app when it's hidden. you will face an ActivityNotFoundException. to make it work, you should unhide icon before doing anything to your main activity and hide it again after you are finished.
I hope anyone can help me or give me a clear solution,
I have an app that I don't want to be opened directly from the user, so I need to hide its icon.
and in the other hand, I want to access this application from another app (App2), so I wrote this code in the function of onClick of a certain button of App2:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(package name of the first app );
startActivity(launchIntent);
Before hiding the App1 , everything was working perfectly No errors but after hiding it using the following code, it crashes:
PackageManager packageManager = this.getPackageManager();
ComponentName componentName = new ComponentName(this,FingerActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
and the following error appear in Android Studio:
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.neurotec.samples.multibiometric/.fingers.FingerActivity }
Error type 3 Error: Activity class
{com.neurotec.samples.multibiometric/com.neurotec.samples.multibiometric.fingers.FingerActivity}
does not exist.
any idea?
any idea?
You disabled the component. You cannot start the component from any other app.
I have an app that I don't want to be opened directly from the user, so I need to hide its icon.
The simplest way for it to not have an icon is for you to not give it an icon. Change your <intent-filter> for that activity to be something custom for you, rather than having it have the MAIN/LAUNCHER values that causes home screens to put an icon for it in the launcher.
I am using device default lock screen in my app for activating and deactivating screen lock. In my application I used a check box which shows that screen lock is activated or not.
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
I am receiving it callback in my DeviceAdminReceiver class.
Methods:onPasswordChanged onPasswordFailed onPasswordSucceeded
Now if user selects none or press back none of these methods get called. I am not able to identify is screen is locked or not ? I used OnActivityResult for handling callback in my Activity, it works fine for back pressed(resultcode 0) but gives same results for all other options.
I found this link which tells that it can't be handled externally.
Summary: I wants to handle screen lock options directly from my application.
if we set password quality on that case user can not able to select none password option
Might it will help you .
We can do this in this way
private ComponentName mDeviceAdmin;
private DevicePolicyManager mDPM;
mDPM.setPasswordQuality(mDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
mContext.startActivity(intent);
My activity gets set as the default Home by the user, but I want to be able to launch the default Home from within my activity as well. I've tried hard coding the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
PackageManager pm = getPackageManager();
String packageName = "com.android.launcher";
String className = "com.android.launcher.Launcher";
final ComponentName cn = new ComponentName(packageName, >className);
intent.setComponent(cn);
This seems to work on my droid, but force closes on the HTC Ally. I'm thinking there's an easier way to just get a list of the apps that have the category Home and Default.
For those that have used the Home Swittcher app. I essentially want to generate that list of installed default Home activities on the phone.
Step #1: Create an Intent that launches whatever the user has for the default HOME application. In other words, do not try putting in the ComponentName.
Step #2: Call queryIntentActivities() on PackageManager to find out who all can respond to that Intent.
Step #3: If there are only two entries in the list, find out which is yours, and the other one is the platform's. If there are 3+ entries in the list, remove yours and let the user choose among the remaining options.
You could sorta combine #2 and #3 by using queryIntentActivityOptions() if you like, setting it up to filter your own Intent out of the list.