I am trying to use ITelephony.aidl in my application. Using this i want to answer the incoming call. I managed to use endcall() and it works perfectly. But when i try to use answerringingcall() it throws error and says that MODIFY_PHONE_STATE is needed, but cant be used since its only available for system apps.
So is there any way of making this work on android 2.3 and above?or is there any other way for answering calls ?
thanks in advance:)
here's my code.
`
public void callAnswer(){
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.answerRingingCall();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}`
and this is my ITelephony.aidl file
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
}
must add permission uses-permission android:name="android.permission.MODIFY_PHONE_STATE"
May be #pra16 you have found a way to accept a call. If not check out this link.The headset keyevent hack worked fine for me . I tested it on android 4.3
Related
I have a method which copies some files from shared memory to internal app memory using the library FileUtils.
The goal is handling IOException in order not to crash the app: it's acceptable if some files are not copied out of the total number.
In the second snippet below there is the called method where the exception is handled.
I need to know 2 things:
a) is there a way to handle the exception only in the called method
and not also in the calling code?
b) in your opinion the exception handling is correct or do I need to add some other code?
Below is the code:
try {
copyfilesfromshared(context);
} catch (IOException e) {
e.printStackTrace();
}
public void copyfilesfromshared(Context context) throws IOException {
for (int ii = 0; ii < numfiles; ii++) {
try {
FileUtils.copyFileToDirectory(files[ii], dirwrite);
} catch (IOException e) {
e.printStackTrace();
}
}
}
is there a way to handle the exception only in the called method and not also in the calling code?
If you handle the exception in copyfilesfromshared() function you do not need to declare throws IOException
public void copyfilesfromshared(Context context) {
for (int ii = 0; ii < numfiles; ii++) {
try {
FileUtils.copyFileToDirectory(files[ii], dirwrite);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Then you can use it normally, without declarin try {...} catch(...) again:
copyfilesfromshared(context);
in your opinion the exception handling is correct or do I need to add some other code?
This looks fine to me, but better check the signature of FileUtils.copyFileToDirectory if it throws any other exception as well, you maybe want to catch here too.
Beside that, it is totally on your side where you wanna handle the exception, but in general the earlier the better.
Heyy,
For your first question
a) is there a way to handle the exception only in the called method
and not also in the calling code?
There is a choise between throwing the IOException from the called method OR
to implement try/catch inside method.
And thats your problem
You are choosing both options instead of one, So just choose one.
And about 2 question
b) in your opinion the exception handling is correct or do I need to
add some other code?
Exception handeling is best at this moment, So don't think and other thought
And that's all!!
I'm looking for a way to identify the input device that is external.
I notice the Android API for [InputDevice] class have a function called [isExternal]. But when I tried to use it, it tells me that it cannot resolve method. I check the online API reference and notice that the function does not exist. So I wonder why is the function in the API but not in the online reference.
Reference:
https://developer.android.com/reference/android/view/InputDevice.html
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/InputDevice.java
isExternal is a hidden method that is not accessible through the SDK. However, you can still invoke it using java reflection.
public boolean isExternal(InputDevice inputDevice) {
try {
Method m = InputDevice.class.getMethod("isExternal");
return (Boolean) m.invoke(inputDevice);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
}
source: What does #hide mean in the Android source code?
I used the Android built-in sip library to write an app that makes calls via my server. The calls are being made correctly, but most of the time, the calls aren't ended correctly.
This is my code to end the call:
public void stopCalling(){
try {
call.endCall();
call.close();
} catch (SipException e) {
e.printStackTrace();
}
}
But it does not Ended properly.
Is there any other way to ended the sip call.
Can anybody let me know how to hold and unhold active phone call?
I am trying to do it using ITelephony.aidl but unable to hold the call. Here is the code I tried to hold an active call
TelephonyManager tm = (TelephonyManager) CallholdddActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
try{
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
telephonyService = (ITelephony) m.invoke(tm);
//telephonyService.silenceRinger();
// here what should i write , i dont know
//System.out.println(a);
}
catch (Exception e) {
// TODO: handle exception
}
}
It's quite not possible to attain the holding options with ITelephony.aidl, since there is no such method.
It's better to use any methods using the Audio manager to find whether the call is active or not. But the drawback there is that Audio Manager could be used by other applications too. So, there will be a dilemma in knowing the Mode!!
I have a webview in my activity. Now when I use WebView.findAll() method to search text in webview it is not highlighting the matching words.
It works fine in Android 1.6 but is not working in 2.2.
There is an issue in Android issue tracker about this: http://code.google.com/p/android/issues/detail?id=9018
I placed this code right after WebView.findAll(), and it made highlighting working:
try
{
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, true);
}
catch (Throwable ignored){}
In android 4.0.3, seems the setFindIsUp is a private method. So above code won't work. As getMethod() method won't return the private methods. Following is a work-around to call the private method which works for 4.0.3:
try{
//Can't use getMethod() as it's a private method
for(Method m : WebView.class.getDeclaredMethods()){
if(m.getName().equals("setFindIsUp")){
m.setAccessible(true);
m.invoke(view, true);
break;
}
}
}catch(Exception ignored){}