We can hide the android app from launcher by editing manifest XML,but is there any code snippet or example by which we can hide the app and start it by entering some code like ##4444## like that.Any way to do this??
Thanks in advance.
To start your app from dialer you need to do three things:
1. Add receiver to your AdroidManifest.xml
<receiver android:name="com.example.HiddedReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
2. Create BroadcastReceiver as stated in xml. It will intercept EVERY calls number. You just need to scan it for your string and do apropiate action - in this case fire off an intent.
public class HiddenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(android.intent.action.NEW_OUTGOING_CALL)) {
String resultData = getResultData();
if (resultData != null) {
if (resultData.contains("YOURCODE")) {
setResultData(null); // it wont continue calling that number
//HERE CREATE your intent
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
}
}
3. To get this working, you need to tell android you will be using this feature, and to grant permission to process calls from the user at install time.
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
i didnt test it, but this one works like a charm:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Related
I uninstall an app programatically in Android, using an Intent, like you see below:
Uri packageURI = Uri.parse("package:"+packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
Which redirects to a prompt that asks if you want to uninstall the app.
Usually after that you can see a toast in the bottom of the screen saying the app was uninstalled. But I want to be able to be notified so I can remove an uninstall button in a view.
How can I know in the code when the uninstall of the package has been completed? Or if an error occurred? Or even, if user clicked "ok" to uninstall or "cancel" if he changed his mind, how can I know?
Is it possible to know any of this? Is there an alternative way to uninstall a package (without being a system app) and be notified?
Thank you for reading. Lemme know if you need any more information.
Well I ended up finding a solution, when a package is removed there is an intent that can be picked up by a receiver.
In my AndroidManifest
<application
<!--...-->
<receiver
android:name=".UninstalledBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
</application>
Create a UninstalledBroadcastReceiver class that extends a normal BroadcastReceiver
public class UninstalledBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// handle the intent here
}
}
You can check for instance if your package name of the app that was installed matches your own and do something with it. In my case, I put some static fields in the UninstalledBroadcastReceiver, including an interface so that I could perform some callbacks. Don't think you can pass fields in the constructor, since the object is created when the intent is received.
I develop one apps mobile number lock, i want whenever mobile on,or restart or switch on ,or on from the top/left/right button placed on mobile in short whenever mobile screen on my lock activity call, i have no idea to how to call activity at time of mobile on please any one give some related example to start activity at first when mobile on. so my lock dispay to user and then enter number password and lock open ...thanks in advance..
Following is working for me :
enter code here :
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
}
and in menifist file add follwing:
enter code here :
<receiver android:name=".BootReciever">
<intent-filter android:enabled="true" android:exported="true">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
There are multiple ways, to achieve this. One way is you can go through Broadcasting a message for your app, after the boot of your mobile. Try reading:
http://developer.android.com/reference/android/content/BroadcastReceiver.html
Also have look at this thread, this will solve your problem.
How to launch activity on BroadcastReceiver when boot complete on Android
Im currently disabling an application via
setApplicationEnabledSetting(String, int, int)
The application is actually disabling itself.
I would expect upon re-installation of the app, the app would re-enable itself, however this isnt the case.
Is there a particular setting required in the manifest to make this work.
(Ive tried setting enabled=true)
Thanks
Im currently disabling all components apart from a broadcast receiver and am trying to catch the installation process to re-enable all the other components again. Which is nasty to say the least
One way to do this is to listen to package installation broadcasts and take action accordingly.
Listen to Intent.ACTION_PACKAGE_ADDED in your broadcast receiver.
If the newly added package is yours, enable the other components.
Example
Manifest:
<receiver android:name =".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
Receiver:
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
final String packageName = intent.getData().getSchemeSpecificPart();
if (replacing && "my.package.name".equals(packageName)) {
// Re-enable the other components
}
}
}
}
Hope this helps.
I want to get the package name and class name of the received intent, But am not able to get it.
I want to make my app secure so it asks for password before being uninstalled. Only the user who Installed the app knows the password, so only he/she can uninstall the app.
My code for Receiver:
public class PackageReceiver extends BroadcastReceiver {
# Override
public void onReceive (Context context, Intent intent) {
if (intent.getAction().equals("android.settings.APPLICATION_DETAILS_SETTINGS")) {
/ / TODO:
//I want here to get this getAction working and then I want to fetch package and class of the intent
}
}
}
Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<Application
android: icon = "# drawable / ic_launcher"
android: label = "Test">
<Receiver android: name = ". PackageReceiver"
android: label = "# string / app_name">
<intent-filter>
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
<data android:scheme="package" />
</ Intent-filter>
</ Receiver>
</ Application>
Please let me know if I am missing any permission because I can not get this working.
I personally think this behavior is annoying. And for sure it's redundant: there are other mechanisms already on place that tackle the same problem (screen locking, encryption).
I'd only use extra checks when operations are on your side (ie.: delete account, change email, etc).
If I didn't make it to discourage you to do that here's another post that solves the same problem following a similar direction.
When we select a particular app inside the settings screen, a broadcast of the type : android.intent.action.QUERY_PACKAGE_RESTART is fired with package name of the application as an extra. I think you could use that to fire the password dialog.
The receiver code will be something like this :
public void onReceive(Context context, Intent intent) {
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("our_app_package_name")){
//Our app was selected inside settings. Fire Password Dialog.
}
}
}
}
I think intent.getExtra("com.android.settings.ApplicationPkgName") should have the package name
i dont know if its acceptable
setting package by getting packagename from the context of activity
intent.setPackage(context.getPackageName());
and to get package name
intent.getPackage()
I want my application to be activated when the user make a specific call. Is there any way to take information which call is making by user in the same time ( not afterwords ) in order to activate the app at the right time ?
Ok i wrote this code for my case and it works:
public class OutgoingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle) return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if( phonenumber.equals("11111111") ) {
Intent myactivity = new Intent(context, MyKeyboard.class);
myactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myactivity);
}
}
}
In the Manifest i add this:
<receiver
android:name=".OutgoingCallReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I don't really know, but I think that's a really dangerous practice. It all depends on what you intend to do with your app. If it's a recording app, I think you can't even think of developping it, or don't post on the internet about it because it would be illegal in many countries. That's how I see and how I feel your question. About Android there is not 15k places to search, have a look at the android API.
http://developer.android.com/reference/android/provider/CallLog.Calls.html
This, for example, I don't know if it's a real time log, or if it's filled after the call is terminated. But you can search in that direction.