[英]Get the incoming phone number?
i am developing a app that gets the incoming calling number . 我正在开发一个获取来电号码的应用程序。
this is my code through which i am trying to do this . 这是我正在尝试通过它的代码。
package com.example.callchecker;
import android.os.Bundle;
import android.app.Activity ;
import android.content.Context;
import android.telephony.*;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class Main_Activity extends Activity {
String number;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
tv1=(TextView) findViewById(R.id.textView1);
TelephonyManager telephonymanager =
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
//register phone state
PhoneStateListener callstatelestener = new PhoneStateListener() {
public void OnCallStateChanged(int state , String incomingNumber) {
number = incomingNumber;
tv1.setText(number);
// If phone ringing
if(state==TelephonyManager.CALL_STATE_RINGING)
{
Toast.makeText(getApplicationContext(), "Phone Is Riging",
Toast.LENGTH_LONG).show();
}
}
};
telephonymanager.listen(callstatelestener,
PhoneStateListener.LISTEN_CALL_STATE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_layout, menu);
return true;
}
}
but this do not do any thing even when the call is make when i am in this app ... weather i have to make it working in background all the time ????? 但这即使在我使用此应用程序时拨打电话也不会做任何事情...天气我必须使其一直在后台工作?????? and if this is the right way to get the incoming number ???
如果这是获取传入号码的正确方法?
您将在此广泛的教程中找到解决问题所需的所有答案: http : //www.vogella.com/articles/AndroidBroadcastReceiver/article.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.