您的位置:首页 > 其它

Adnroid手机安全卫士

2016-05-03 20:31 363 查看
在做手机安全卫士的时候出现了很多问题,记录下来,方便自己学习。

1.使用SettingItemView继承RelativeLayout的时候。刚开始只继承了父类的一个方法,如下:

<span style="font-size:24px;">public class SettingItemView extends RelativeLayout {

private TextView tvTitle;
private TextView tvDesc;
private CheckBox cbStatus;

public SettingItemView(Context context) {
super(context);
initView();
}

//初始化布局
private void initView(){
//将自定义布局设置给SettingItemView
View.inflate(getContext(), R.layout.view_setting_item,this);
tvTitle= (TextView) findViewById(R.id.tv_title);
tvDesc= (TextView) findViewById(R.id.tv_desc);
cbStatus= (CheckBox) findViewById(R.id.cb_status);
}

public  void setTitle(String title){
tvTitle.setText(title);
}

public void setTvDesc(String desc){
tvDesc.setText(desc);
}

//判断勾选状态
public boolean isChecked(){
return cbStatus.isChecked();
}

//设置勾选状态
public void setChecked(boolean check){
cbStatus.setChecked(check);
}

}
</span>
出现了运行程序闪退的状态,报错java.lang.ClassNotFoundException

修改如下:

public class SettingItemView extends RelativeLayout {

private TextView tvTitle;
private TextView tvDesc;
private CheckBox cbStatus;

public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}

public SettingItemView(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}

public SettingItemView(Context context) {
super(context);
initView();
}

//初始化布局
private void initView(){
//将自定义布局设置给SettingItemView
View.inflate(getContext(), R.layout.view_setting_item,this);
tvTitle= (TextView) findViewById(R.id.tv_title);
tvDesc= (TextView) findViewById(R.id.tv_desc);
cbStatus= (CheckBox) findViewById(R.id.cb_status);
}

public  void setTitle(String title){
tvTitle.setText(title);
}

public void setTvDesc(String desc){
tvDesc.setText(desc);
}

//判断勾选状态
public boolean isChecked(){
return cbStatus.isChecked();
}

//设置勾选状态
public void setChecked(boolean check){
cbStatus.setChecked(check);
}

}
程序正常运行。

2.在跳转手机防盗页面的时候出现了程序闪退,logcat不报错了情况。

<span style="font-size:24px;">  startActivity(new Intent(HomeActivity.this,LostFindActivity.class));</span>


原因:没有在AndroidManifest.xml中注册LostFindActivity.

3.在使用selector的时候,在drawable里的两张图片出现找不到资源的现象



去掉了两张图片中.9的后缀就行了

4.在读取sim卡信息的时候出现不能打印sim卡信息,错误如下:


现在都还不知道是怎么回事? 

今天重新跑了一下,发现可以打印了,可能是ide建项目的问题(猜测)

5.Android收不到开机广播问题

之前代码

<receiver android:name="receiver.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>

</receiver>


之后代码

<receiver android:name="receiver.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter  >
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_EJECT" />

<data android:scheme="file" />
</intent-filter>
</receiver>


处理应用安装在sd后监听不到开机广播的问题,需要同时监听开机广播和sd卡挂载的广播,此外还要看一下是否添加了权限RECEIVE_BOOT_COMPLETED

6.关于assets文件夹的问题

有时候需要放置一些文件而且不被proguard压缩,或者放置数据库文件,可以放到assets目录中,
熟悉了eclipse的ide,在as中创建的项目并不会自动新建assets目录。应该要将文件放到/src/main/assets
否则会出现空指针异常:
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference

7.关于数据库sqlite不支持varchar的问题
在建表的时候遇到这样的问题:



由于在建表时column的packagename 使用了varchar(20)类型 ,导致错误(?),应该使用text类型,
重新测试了一下,发现可能是建表的时候出现了问题,卸载app之后,再重装发现是可以支持varchar的

8.关于ActivityManager方法不能使用的问题



可能是as导包的问题,需要自己手动导包import android.app.ActivityManager; 
才能使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: