android: 保存联系电话并在应用程序中访问
android: save contact number and access it in app
我正在制作一个应用程序,允许特定号码响铃,而 phone 静音,并且我能够在特定号码校准时成功更改 phone 状态。现在我需要访问联系人详细信息,保存它们并让应用程序在该号码呼叫时访问它,以便我的应用程序可以更改其声音状态。请帮助我了解资源、想法、做什么等。我也提供了我的应用程序代码......
public class MainActivity extends BroadcastReceiver {
Context pcontext;
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tmngr= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
pcontext=context;
MyPhoneStateListener PhoneListener = new MyPhoneStateListener(pcontext);
tmngr.listen(PhoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
private class MyPhoneStateListener extends PhoneStateListener {
public MyPhoneStateListener(Context pcontext) {
// pcontext=context;
}
public void onCallStateChanged(int state,String incoming)
{
AudioManager am=(AudioManager)pcontext.getSystemService(Context.AUDIO_SERVICE);
String mode = "";
if (state == 1) {
String msg = "New Phone Call Event. Incomming Number : "+incoming;
int duration = Toast.LENGTH_SHORT;
// Context pcontext;
if(incoming.equals("9588840")||incoming.equals("+9195648840"))
{
Toast toast;
toast = Toast.makeText(pcontext, msg, duration);
toast.show();
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
{ mode="NORMAL_MODE";}
Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
}
else
{
if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
{ mode="SILENT_MODE";}
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
}
}
}
}
}
您应该从 Contacts in general. Then you can make changes. Here is some example 开始。
经过几天的研究,我做出了 app.for 它的开发,我使用 sqlite 来保存数据库,我将参考
http://www.tutorialspoint.com/android/android_sqlite_database.htm
之后我制作了一个动态广播接收器,当我使用的动态广播接收器的呼叫状态正在响铃时将使用它
http://androidexample.com/Incomming_Phone_Call_Broadcast_Receiver__-_Android_Example/index.php?view=article_discription&aid=61&aaid=86
在从联系人获取数据并使用游标将传入号码与每个条目进行比较后,我能够制作该应用程序。
感谢堆栈成员和团队的帮助
我正在制作一个应用程序,允许特定号码响铃,而 phone 静音,并且我能够在特定号码校准时成功更改 phone 状态。现在我需要访问联系人详细信息,保存它们并让应用程序在该号码呼叫时访问它,以便我的应用程序可以更改其声音状态。请帮助我了解资源、想法、做什么等。我也提供了我的应用程序代码......
public class MainActivity extends BroadcastReceiver {
Context pcontext;
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tmngr= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
pcontext=context;
MyPhoneStateListener PhoneListener = new MyPhoneStateListener(pcontext);
tmngr.listen(PhoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
private class MyPhoneStateListener extends PhoneStateListener {
public MyPhoneStateListener(Context pcontext) {
// pcontext=context;
}
public void onCallStateChanged(int state,String incoming)
{
AudioManager am=(AudioManager)pcontext.getSystemService(Context.AUDIO_SERVICE);
String mode = "";
if (state == 1) {
String msg = "New Phone Call Event. Incomming Number : "+incoming;
int duration = Toast.LENGTH_SHORT;
// Context pcontext;
if(incoming.equals("9588840")||incoming.equals("+9195648840"))
{
Toast toast;
toast = Toast.makeText(pcontext, msg, duration);
toast.show();
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
{ mode="NORMAL_MODE";}
Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
}
else
{
if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
{ mode="SILENT_MODE";}
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
}
}
}
}
}
您应该从 Contacts in general. Then you can make changes. Here is some example 开始。
经过几天的研究,我做出了 app.for 它的开发,我使用 sqlite 来保存数据库,我将参考 http://www.tutorialspoint.com/android/android_sqlite_database.htm 之后我制作了一个动态广播接收器,当我使用的动态广播接收器的呼叫状态正在响铃时将使用它 http://androidexample.com/Incomming_Phone_Call_Broadcast_Receiver__-_Android_Example/index.php?view=article_discription&aid=61&aaid=86 在从联系人获取数据并使用游标将传入号码与每个条目进行比较后,我能够制作该应用程序。 感谢堆栈成员和团队的帮助