Reject Incoming calls in android [duplicate] - android

I want to block calls from few numbers, for that I want to write a app of my own.
So what are the APIs which I should be using?
Basically I want to get notified when a call comes, i want to compare numbers if it is what i want to block, i want to cut the call or mute it or if possible mute it and record it.

OMG!!! YES, WE CAN DO THAT!!!
I was going to kill myself after severe 24 hours of investigating and discovering... But I've found "fresh" solution!
// "cheat" with Java reflection to gain access to TelephonyManager's
// ITelephony getter
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony)m.invoke(tm);
all all all of hundreds of people who wants to develop their call-control software visit this start point
there is a project. and there are important comments (and credits)
briefly: copy aidl file, add permissions to manifest, copy-paste source for telephony management )))
Some more info for you. AT commands you can send only if you are rooted. Than you can kill system process and send commands but you will need a reboot to allow your phone to receive and send calls =)))
I'm very hapy =) Now my Shake2MuteCall will get an update !

It is possible and you don't need to code it on your own.
Just set the ringer volume to zero and vibration to none if incomingNumber equals an empty string. Thats it ...
Its just done for you with the application Nostalk from Android Market. Just give it a try ...

In android-N, this feature is included in it. check Number-blocking update for android N
Android N now supports number-blocking in the platform and provides a
framework API to let service providers maintain a blocked-number list.
The default SMS app, the default phone app, and provider apps can read
from and write to the blocked-number list. The list is not accessible
to other app.
advantage of are:
Numbers blocked on calls are also blocked on texts
Blocked numbers can persist across resets and devices through the
Backup & Restore feature
Multiple apps can use the same blocked numbers list
For more information, see android.provider.BlockedNumberContract
Update an existing project.
To compile your app against the Android N platform, you need to use the Java 8 Developer Kit (JDK 8), and in order to use some tools with Android Studio 2.1, you need to install the Java 8 Runtime Environment (JRE 8).
Open the build.gradle file for your module and update the values as follows:
android {
compileSdkVersion 'android-N'
buildToolsVersion 24.0.0 rc1
...
defaultConfig {
minSdkVersion 'N'
targetSdkVersion 'N'
...
}
...
}

You could just re-direct specific numbers in your contacts to your voice-mail. That's already supported.
Otherwise I guess the documentation for 'Contacts' would be a good place to start looking.

You can do it by listening to phone call events . You do it by having a BroadcastReceiver to PHONE_STATE and to NEW_OUTGOING_CALL. You find there what is the phone number.
Then when you decide to end the call, this is a bit tricky, because only from Android P it's guaranteed to work. Check here.

Related

Enable Bluetooth without auto-connecting to devices ("quietly") in Android

I found out there's a system function called IBluetoothManager.enableNoAutoConnect(), which by the name, seems to do exactly what I've been searching for hours: enable Bluetooth without auto-connecting to devices.
I can call the function, but...
java.lang.SecurityException: no permission to enable Bluetooth quietly
Because...
if (callingAppId != Process.NFC_UID) {
throw new SecurityException("no permission to enable Bluetooth quietly");
}
So, is there any other way of calling this function? Like some ADB command? Or through another class? I also found a function that does the same here, in AdapterService.java. But I don't know how to get to it (doesn't even appear on Android Studio).
Note: I have root and system-privileged permissions (just not signature ones), and I'm using the internal/hidden SDK, so I have access to the classes and everything without needing reflection (and still, AdapterService doesn't show up - unless there's a problem with the "SDK" and it's not showing all it should?).
(PS: I say "quietly" in the title because in the source, the variable that tells if it's auto-connect or not is called quietMode.)
EDIT: actually the function is directly in BluetoothAdapter, without needing to go for the interface. Not sure how I didn't notice it. But anyway, same problem.
EDIT 2: more specifically for Android Oreo and below (or Pie and below), as I just found a function called setSilenceMode() on BluetoothDevice, and it might do what I'm wanting (not tested), but still, missing on older APIs.
Thank you

Detect application is being uninstalled in lollipop devices

I would like to know which users have uninstalled my application so that I can ask them for a feedback to improve the app. Hence, I would like to detect when the user has initiated the uninstallation process on my app.
One of the older solutions on StackOverflow had the following steps:
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(MAX_PRIORITY);
String activityName = taskInfo.get(0).topActivity.getClassName();
if (activityName.equals("com.android.packageinstaller.UninstallerActivity")) {
// do whatever is needed
Since Lollipop, getRunningTasks has been deprecated. So how can com.android.packageinstaller.UninstallerActivity activity be detected without getRunningTask?
Alternatively is there any other method to detect uninstallation process has been started on my app? Using getAppTask probably?
Apparently you wont be able to do this, you will have to rely on something called silent notification.
What we did was we sent notification every 3 days or whatever frequency you want.
On the client side as soon as a notification is received we hit a network call which mark NotificationReceived for the client. Now since notification are not full proof we assumed a threshold of 2/3 missed notification as uninstall event. And for the client we have this counter above decided threshold we contacted them for feedback.
Also no one will be willing to fill your form at the time of uninstallation as user has already decided to uninstall your application.
Read these 2 questions and answers:
native solution
GCM solution
As I know you have to mix the two. Read the limitations of first solution. You have to confirm uninstallation event of the first solution with the second solution for a complete implementation.
Hopefully, this solution will work for you. It helps you understand the reasons for your app uninstalls, reduce the uninstall rate using a powerful predictive engine and also get app Re-installs through a unique actionable channel (Android version 4.0 and above).
Just set a variable named appLastPresent for every user in the server-side and update that variable every day by calling an API using WorkManager's PeriodicWorkRequest. Also set installedDate variable when the user installs the app.
Now set up a chron job on the server side to check if the difference between installedDate and appLastPresent is greater than 7 days. Then send the user an email or message enquiring for issues or feedback, if it is greater.
NB: User can be offline for 7 days. Therefore only send email enquiring like why you are not using the app, if uninstalled please let us know why

Which android API calls need these permission?

I'm trying to figure out which android API calls need these permissions:
android.permission.HARDWARE_TEST
android.permission.DEVICE_POWER
android.permission.DIAGNOSTIC
android.permission.GET_TOP_ACTIVITY_INFO
I read the descriptions on the Android developer website, but I found no way to perform the operations that these permissions allow.
EDIT after HexAndBugs answer: I know these permission are not intended for third-party application, but I'd like to use them in a experimental environment, playing the role of the manufacturer.
These aren't intended to be used in your apps (unless you are a device manufacturer), so you won't find things that need them in the API. Note that they all say Not for use by third-party applications. See, for example, DEVICE_POWER
Although these settings are not for usual app but if you have a rooted device and you need to control, lets say hardware test then you would have to add it to your apps permisson and override the ususal CET testing pannel
But FYI it can brick the phone or device if you tweaksomething wrong so beaware;
i personally have used couple of these permisson for e.g getTop Activity info to monitor that my app is always on foreground

Detect Outgoing Calls Reject Reason in Android

Is is possible to detect network reject reason for outgoing calls in Android?
For example, let's assume a person is out of credit and is attempting a phone call. In this case, the Network will reject the call (since the person is out of credit). How can an App detect this?
Thanks!
A "bit" late xD, but I believe you're looking for this: https://android.googlesource.com/platform/frameworks/base/+/master/telephony/java/android/telephony/DisconnectCause.java. I just found it with help of what you said on one of the error codes: "Network is busy" --> searched "network is busy site:android.googlesource.com" on Google, without the quotes (saying this because they matter on Google searches, in case anyone didn't know).
That's DisconnectCause class and there's also PreciseDisconnectCause: https://android.googlesource.com/platform/frameworks/base/+/master/telephony/java/android/telephony/PreciseDisconnectCause.java. You can know this last one because on the first one, it's said that class is used on PhoneStateListener on onCallDisconnectCauseChanged() (which may be what you want), and on Android Developers, we can see that method has 2 parameters, which give 404 error on Android Developers. So I seached the .java class file on Google for Android Source links and there they are.
Notes on using this method:
it requires API 30 at minimum (pity...);
but more important, it requires READ_PRECISE_PHONE_STATE (the app must be installed as system app) - or some other trick with root commands.

Change android phone's System date on button click from android application

I trying some stuffs with android as i am learning android development, now i have a scenario here.
I want to change the android phone's system date through my application( first i would like to know is this doable? )
Layout is as below
Now what i want is when the user clicks the button the date should increase by say 20 days
how can i do this.
i am unable to start...please help
As I already said that's impossible. You need the SET_TIME permission and that permission is granted by system only to applications that are in the Android system image. If You are able to gain that privilege you can easily change with the AlarmManager. SystemClock.setCurrentTimeMillis write the /dev/allarm file
adb shell ls -l /dev/alarm
crw-rw-r-- system radio 10, 46 2013-06-12 10:46 alarm
c stays for Character special file (stored in /dev).
system is the owner of the file
radio is the group
system and radio have read and write permissions (rw-, tree bits, int value 6), the others have only the read permission (r, int value 4). So the file permission is 664. If you can get root user (running su), you can change the permission of this file and wrote in it a new value. A bug report has been filled in order to ask google to allow apps to modify programmatically the mobile date but it has been declied. Here the reference
On Android, the only way for an application do have write access to the time&date is to get the SET_TIME permission, which is only possible for "applications that are in the Android system image or that are signed with the same certificate as the application that declared the permission." (see signatureOrSystem protection level).
The only way for your application to reach this protection level is to run on a rooted device, or build and sign your own android rom.
If this is your case, you can easily use the AlarmManager or simply the Calendar instance.
Good luck!
Normal user applications does not have permission to change the device time. Read the answer by cashbash in the following post for the alternate option.
Unfortunately, blackbelt is right; android lets us do a lot of cool things, but changing system time programmatically is not one of them.
Since I see that you are looking for more credible/official sources, I suggest you check out this open ticket with Google, which suggests this is an open problem--it ought to work, but doesn't, and it doesn't seem Google is going to fix it anytime soon. The gist of it is that the SET_TIME protection level is set higher than it ought to be. (for more information on permissions, see here)
Although this is not quite the same as changing the time programmatically, you can still make the user change the system time for you if for some reason you do need system time to be changed. This thread will explain how to go about implementing that if you want to go that route.
Hope this was helpful information!

Categories

Resources