16,018,394 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by user1992 (Top 8 by date)
user1992
1-Dec-13 14:54pm
View
how include onReceive() in my code so that when call incoming have to be reject with a automatic message.??
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING)
{
Toast.makeText(getApplicationContext(),"Phone Is Riging", Toast.LENGTH_LONG).show();
contactExists(getApplicationContext(),incomingNumber);
}
if(state==TelephonyManager.CALL_STATE_OFFHOOK)
{
Toast.makeText(getApplicationContext(),"Phone is Currently in A call", Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_IDLE)
{
Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call", Toast.LENGTH_LONG).show();
}
}
};
telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
user1992
1-Dec-13 9:58am
View
Thanks bharat Parsiya,
I try this example and my code has crash. I think that the problem is because i use:
( https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/)
import com.android.internal.telephony.ITelephony;
Do you have in mind another solution for this problem ??
Maybe by using official android SDK?
user1992
18-Nov-13 16:19pm
View
in start has a text NOT DETECTING
after that it haw 2 buttons
the first is - Turn on
and the last is - exit
when i press Turn on the button message become turn off and the starting message become DETECTING
Finally when i press exit the starting message become NOT DETECTING and the app is exit.
i run this code on simulator so i don't know if the output was different if i had device..
user1992
18-Nov-13 16:10pm
View
Deleted
@Override
public void onReceive(Context context, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(ctx,
"Outgoing: "+number,
Toast.LENGTH_LONG).show();
}
}
private Context ctx;
private TelephonyManager tm;
private CallStateListener callStateListener;
private OutgoingReceiver outgoingReceiver;
public CallHelper(Context ctx) {
this.ctx = ctx;
callStateListener = new CallStateListener();
outgoingReceiver = new OutgoingReceiver();
}
/**
* Start calls detection.
*/
public void start() {
tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);
}
/**
* Stop calls detection.
*/
public void stop() {
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
ctx.unregisterReceiver(outgoingReceiver);
}
}
ListenCallExample Manifest
--------------------------
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
="" package="com.example.listencallexample" android:versioncode="1" android:versionname="1.0">
<uses-sdk
android:minsdkversion="8"
="" android:targetsdkversion="17">
<uses-permission android:name="android.permission.READ_PHONE_STATE">
<application
android:allowbackup="true"
="" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity
android:name="com.example.listencallexample.MainActivity"
="" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
user1992
18-Nov-13 16:06pm
View
MainActivity.java
--------------------
package com.bitgriff.androidcalls;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
* Main activity, with button to toggle phone calls detection on and off.
*
*/
public class MainActivity extends Activity {
private boolean detectEnabled;
private TextView textViewDetectState;
private Button buttonToggleDetect;
private Button buttonExit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewDetectState = (TextView) findViewById(R.id.textViewDetectState);
buttonToggleDetect = (Button) findViewById(R.id.buttonDetectToggle);
buttonToggleDetect.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setDetectEnabled(!detectEnabled);
}
});
buttonExit = (Button) findViewById(R.id.buttonExit);
buttonExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setDetectEnabled(false);
MainActivity.this.finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void setDetectEnabled(boolean enable) {
detectEnabled = enable;
Intent intent = new Intent(this, CallDetectService.class);
if (enable) {
// start detect service
startService(intent);
buttonToggleDetect.setText("Turn off");
textViewDetectState.setText("Detecting");
}
else {
// stop detect service
stopService(intent);
buttonToggleDetect.setText("Turn on");
textViewDetectState.setText("Not detecting");
}
}
}
CallDetectService.java
-----------------------
package com.bitgriff.androidcalls;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
/**
* Call detect service.
* This service is needed, because MainActivity can lost it's focus,
* and calls will not be detected.
*
*/
public class CallDetectService extends Service {
private CallHelper callHelper;
public CallDetectService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
callHelper = new CallHelper(this);
int res = super.onStartCommand(intent, flags, startId);
callHelper.start();
return res;
}
@Override
public void onDestroy() {
super.onDestroy();
callHelper.stop();
}
@Override
public IBinder onBind(Intent intent) {
// not supporting binding
return null;
}
}
CallHelper.java
----------------
package com.bitgriff.androidcalls;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;
/**
* Helper class to detect incoming and outgoing calls.
*
*/
public class CallHelper {
/**
* Listener to detect incoming calls.
*/
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// called when someone is ringing to this phone
Toast.makeText(ctx,
"Incoming: "+incomingNumber,
Toast.LENGTH_LONG).show();
break;
}
}
}
/**
* Broadcast receiver to detect the outgoing calls.
*/
public class OutgoingReceiver extends BroadcastReceiver {
public OutgoingReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Str
user1992
18-Nov-13 15:56pm
View
Can you tell me please where can i found more details about how can i call the methods that include these source code from the android's API so that i can develop new operations with them?
user1992
18-Nov-13 14:56pm
View
I look for these source codes and i can't find more details about them.
Can you tell me please where can i found more details about how can i call them from the android's API so that i can develop new operations with them?
user1992
18-Nov-13 13:37pm
View
For these reason, i look for these codes and i can't find it somewhere. so i can't develop my own app that rely on this operations.
After these operations i have to reject automatically the call and send a predefined message to incoming contact if it exists in my phone contact list.
Can you tell me please where can i found these codes and working with expected behavior?
Show More