小知识:android


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;
	}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值