使用adb命令时的错误
127|shell@android:/ $ cd /data cd /data shell@android:/data $ ls ls opendir failed, Permission denied你是没有权限的。
shell@android:/data $ run-as com.your.package run-as com.your.package shell@android:/data/data/com.your.package $ cd /data/data/com.your.package cd /data/data/com.your.package shell@android:/data/data/com.your.package $ ls ls cache databases lib shared_prefs shell@android:/data/data/com.your.package $ cd databases cd databases shell@android:/data/data/com.your.package/databases $ ls yourpackagename.db $ cat preferences.db > /mnt/sdcard/yourpackagename.db将你要访问的package目录下的db文件拷贝到sdcard中,这样就可以正常访问了!
实现思路: 1用Service 监听来电 2 用WindowManager作为显示 3把号码归属地放入数据库
public class AddressService extends Service {
public static final String TAG = "AddressService";
private TelephonyManager manager;
private MyPhoneListener listener;
private WindowManager windowmanager ;
private SharedPreferences sp;
private View view;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
listener = new MyPhoneListener();
sp = getSharedPreferences("config", MODE_PRIVATE);
windowmanager = (WindowManager) this.getSystemService(WINDOW_SERVICE);
// 注册系统电话管理服务的监听器
manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
manager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
private class MyPhoneListener extends PhoneStateListener{
// 电话状态发生改变的时候 调用的方法
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE: // 处于静止状态: 没有呼叫
if(view!=null){
windowmanager.removeView(view);
view = null;
}
// 再获取一次系统的时间
break;
case TelephonyManager.CALL_STATE_RINGING: // 零响状态
Log.i(TAG,"来电号码为"+ incomingNumber);
String address = NumberAddressService.getAddress(incomingNumber);
Log.i(TAG,"归属地为"+ address);
//Toast.makeText(getApplicationContext(), "归属地为"+ address, 1).show();
showLoaction(address);
// 获取一下当前系统的时间
break;
case TelephonyManager.CALL_STATE_OFFHOOK: //接通电话状态
if(view!=null){
windowmanager.removeView(view);
view = null;
}
break;
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
manager.listen(listener, PhoneStateListener.LISTEN_NONE);
listener = null;
}
/**
* 在窗体上显示出来位置信息
* @param address
*/
public void showLoaction(String address) {
WindowManager.LayoutParams params = new LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.type = WindowManager.LayoutParams.TYPE_TOAST;
params.setTitle("Toast");
params.gravity = Gravity.LEFT | Gravity.TOP;//如果不指定,默认是居中的。
params.x = sp.getInt("lastx", 0);
params.y = sp.getInt("lasty", 0);
view = View.inflate(getApplicationContext(), cn.itcast.mobilesafe.R.layout.show_location, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_location);
int backgroundid = sp.getInt("background", 0);
if(backgroundid==0){
ll.setBackgroundResource(R.drawable.call_locate_gray);
}else if(backgroundid==1){
ll.setBackgroundResource(R.drawable.call_locate_orange);
}else {
ll.setBackgroundResource(R.drawable.call_locate_green);
}
TextView tv = (TextView) view.findViewById(R.id.tv_location);
tv.setTextSize(24);
tv.setText(address);
windowmanager.addView(view , params);
}
}
前不久一个朋友问在win8中有没有MessageBox来弹出一个对话框提示,当时也不知道,今天发现了MessageDialog才知道可以这样子操作;在win8中是没有对话框的概念了的,
MessageDialog实际上弹出的是一个层,我们可以通过这些代码来实现这个弹出层的功能:
MessageDialog dlg = new MessageDialog("删除成功","提示");//“删除成功”是弹出的提示,"提示"是一个标题 dlg.ShowAsync();
实现的效果如下图:
右边的“关闭”按钮还是比较人性化的,方便触摸操作。