i wish to end an incoming call programmatically through my app. after searching i got the code which uses com.android.internal.telephony but says it wont work for versions higher than 2.3.
i got the code for attending a call through key press event
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);
i.putExtra(Intent.EXTRA_KEY_EVENT, event );
context.sendOrderedBroadcast(i, null);
is there any similar method available for ending a call?? plz help
check out this link for carrying it out on a honeycomb device after that its deprecated and it won't work however,here's a trick to handle that
http://prasanta-paul.blogspot.in/2010/09/call-control-in-android.html
Solution
You make a window appear as soon as you get a broadcast for incoming call and place your END call button on the same position as the default android end call button in center so user presses your button but you will pass the event below that window and hence call ends by android but You become a winner..
heres a tutorial for creating a window anywhere you want to without starting an activity for it...
http://www.piwai.info/chatheads-basics/#AndroidHead
Related
I'm making an app in which you can chat and call with other contacts. But in case of calling, I've designed the app in such a way that after typing the number and clicking on the call icon, it takes you to native calls app for calling and updates the call log in my current app.
For this process, this is the code I've written:
if (nativeCall(mobileNumber)) {
Intent intent = new Intent(Intent.ACTION_CALL).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + mobileNumber));
if (((BaseActivity) context).isNetworkOk()) {
addToUserCallLogs(context, DateUtils.convertTimestampToDate(), contactUri, "Out", System.currentTimeMillis());
}
context.startActivity(intent);
return true;
}
You can see that I'm putting mobile number into the intent and starting it. And I'm using addToUserCallLogs() function to show it in my app's call logs.
This works fine usually, but in the issue is in the following case.
When the user has multiple calling applications(For eg, the user has installed application named SMARTalk. Now he has native caller app and SMARTalk app to call from), in that case the Android system gives options to chose from like this:
Now, if he choses from one of them, even in that case there is no issue. Say he didn't chose any of those and clicked on the other part of the screen. Then this options bar will be closed. Since all this is happening after starting the intent, this call will be added in the call logs of the app from the function addToUserCallLogs(). But I don't want the call to be shown in the call Logs because I haven't done any call.
But according to the code I've written, before starting the intent, I'm adding into my app's call logs database. Is there a way the information of whether the call has happened or not can be sent back from the system to the app?
Or a way to get these options to be shown manually from the app?
Please comment if you need any more explanation.
I guess no way to receive the callback information because ACTION_CALL does not return a result. You can see the output is nothing from docs even you use startActivityForResult
I'm working on Accessibility Service, but I'm not getting events of app start. I am using TYPE_VIEW_FOCUSED currently. Please let me know how can I get events of when any app starts.
info.eventTypes = AccessibilityEvent.TYPE_VIEW_FOCUSED;
You can try using AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED .. It will trigger when top application has changed.
fun onAccessibilityEvent(event: AccessibilityEvent) {
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
event.packageName // Top application package name
}
}
Disclaimer - I never tried this code. I was reading about AccessibilityService since last few days. So let me know if it works or not .. i'll gladly remove this answer if its not correct. have a look at This Sample..
ADM's code indeed works - but just be aware that you may get more than one TYPE_WINDOW_STATE_CHANGED event for each app.
For example, when I launch Chrome, my app receives two events within milliseconds of each other. The first is for "ClassName: android.widget.FrameLayout" and the second for "ClassName: org.chromium.chrome.browser.ChromeTabbedActivity".
When I launch YouTube, my app receives four events in rapid succession: "ClassName: android.widget.FrameLayout", "ClassName: android.widget.ImageView", "ClassName: android.widget.FrameLayout", "ClassName: com.google.android.apps.youtube.app.watchwhile.WatchWhileActivity".
In either case, only one event has "FullScreen: true", so maybe you can filter on that.
I have a basic Activity which mainly allows the user to change settings and save them. I also have a BroadcastReceiver which is launched on SMS_RECEIVED.
The main point of the app is to vibrate whenever a certain message is received until the user taps a button to make it stop. The activity is only there to allow the user to change settings and press the "Stop" button.
In my onReceive method (BroadcastReceiver), I get the content of the last message received and make the phone vibrate if the message is equal to a certain string. All of that is working perfectly, the problem is when I want to make it stop. Right now, I'm trying to make a "Stop" button appear in the Activity when the phone starts vibrating.
I understand that UI elements should remain in the Activity and so what I'm trying to do is communicate between the Activity and my BroadcastReceiver. I've found here how to do that with an Observer. The problem though is that I want the app to function at any time, even at boot time. It's very easy with a BroadcastReceiver but since it requires the Activity to be shown to allow the user to stop the vibration, I have to start the activity if it isn't started already.
So what I do is this:
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("SMSReceived", true);
context.startActivity(i);
ObservableObject.getInstance().updateValue(true);
The problem is, when there is no instance launched, it creates a new one and sends the extra boolean correctly but the updateValue method doesn't seem to get called at all (due to the previous instance I suppose?) and inversely, when there is an instance launched (in the background) the extra boolean doesn't get passed and the updateValue method gets called correctly.
I suppose I could just launch the Activity on boot and immediately put it in the background but it could cause problems if the user closes the application, at which point it would simply stop working until the user started it again since the Observer would have no instance to send data to.
Do you guys have any idea of what I could do to solve my problem?
If it's not clear I can try to explain further.
My app starts an intent to call calendar app inserting an events with these codes
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(Events.DTSTART, date.getTime())
.putExtra(Events.DTEND, date.getTime() + DateUtils.HOUR_IN_MILLIS)
.putExtra(Events.EVENT_TIMEZONE, TimeZone.getDefault().getDisplayName());
startActivityForResult(intent,EDIT_EVENT_AGENDAUI);
//startActivity(intent); dosent make any difference
As you can see here, it calls a calendar insert page.
but it is weird that it wont go back to my app instead of go back to calendar view
after i click "Done". I have to click "back" button on screen to return to my app
this is kinda unfriendly
googled a half day
it seems no one gets this problem.
Any ideas? Thanks
PS
i am using Android ICS on Virtual Machine
if i click "cancel" to quit the page, it acts as i expected -- go back to my app. This is good, but much more confused me.
What you are experiencing is the correct behavior. I'm not aware of any shortcut for just adding an event without going into the calendar activity, unless there are some public content provider for the calendar.
Especially in ICS the add-event window might just be a Fragment included in the calendar activity, so it makes perfect sense that you see your event after you have clicked save.
I would like to add details to the incoming call screen on android.
lets say I have a string 'x', so I want 'x' to show up on the incoming call screen under the name of the person who is currently calling.
I know this is possible because of these apps:
CallerId,
Vringo
I'm pretty new to this area, so I need to know what is the process to achieve that, for example: get the event of incoming call, go to the incoming call interface and so on.
Thanks!
I think you have to look at the intent receivers (actually called intent filter => have to be defined in your manifest), there should be one for incoming calls. And then you define your own application, with an activity that is made to receive this kind of intent and with the design you like...
if i'm not mistaken, it should be this :
ACTION_ANSWER
you can find more doc here and there.
CallerId seems to show Toast on the Call screen or they maybe use WindowManager addView methods (i think Vringo is working in a such way). The most problem in such case is to know that Call Screen is now on the foreground.