android EditText 的输入监听
EditText keyEdit = (EditText) GetSubView(R.id.searchkey);
keyEdit.addTextChangedListener(watcher);
private TextWatcher watcher = new TextWatcher(){
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
Log.d("TAG","[TextWatcher][onTextChanged]"+s);
}
public void afterTextChanged(Editable s) {
}
};
打电话
Uri uri = Uri.parse("tel:" + "15950521838");
Intent intent = new Intent(Intent.ACTION_CALL, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
判断当前的场景或服务
public boolean getCurrentSence(Context mContext) {
boolean sence = false;
try {
ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
if ("com.pateo.music.app.NetMusicPlayer"
.indexOf(cn.getClassName()) >= 0) {
sence = true;
}
} catch (Exception e) {
Log.d(TAG, "" + e);
}
return sence;
}
private boolean isStartService(Context ctx,String igrsClassName) {
Log.d(TAG, "isStartService : igrsClassName " + igrsClassName );
ActivityManager mActivityManager = (ActivityManager) ctx
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> currentService = mActivityManager
.getRunningServices(100);
boolean b = igrsBaseServiceIsStart(currentService, igrsClassName);
return b;
}
private boolean igrsBaseServiceIsStart(
List<ActivityManager.RunningServiceInfo> mServiceList,
String className) {
Log.d(TAG, "igrsBaseServiceIsStart : className " + className );
String serviceClassName;
for (int i = 0; i < mServiceList.size(); i++) {
serviceClassName = mServiceList.get(i).service.getClassName();
Log.d(TAG, "serviceClassName : " + serviceClassName);
if (className.equals(serviceClassName)) {
return true;
}
}
return false;
}
数据变动监听
getContentResolver().registerContentObserver(Contacts.People.CONTENT_URI, true,
new ContentObserver(new Handler()) {
public void onChange(boolean selfChange) {
Log.d(TAG,"========= Received Contacts Changes Notification========");
addContactsToGrammer();
super.onChange(selfChange);
}
});
应用下的xml文件的全局保存
String times = getSharedPreferences("voice_first",
PreferenceActivity.MODE_WORLD_WRITEABLE | PreferenceActivity.MODE_WORLD_READABLE)
.getString("times", "0");
getSharedPreferences("voice_first",
PreferenceActivity.MODE_WORLD_READABLE)
.edit().putString("times", "1")
.commit();
判断是否通话中
private boolean phoneIsInUse() {
boolean phoneInUse = false;
try {
ITelephony phone = ITelephony.Stub.asInterface(ServiceManager
.checkService("phone"));
if (phone != null)
{
phoneInUse = !phone.isIdle();
}
} catch (RemoteException e) {
Log.w(TAG, "", e);
}
Log.d(TAG,"phoneIsInUse() phoneInUse ======" + phoneInUse);
return phoneInUse;
}