package zy.dnh;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class getpowerinfo extends BroadcastReceiver{
FileOutputStream out;
final public String ONPATH = "/data/data/zy.dnh/on.txt";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent bootActivityIntent=new Intent(context,mService1.class);//启动服务
bootActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
writefile("0,0,0,0,0,0,0,0,0,0,0,0",ONPATH);
context.startService(bootActivityIntent);
Toast.makeText(context, "Netcounter service has been lauched", Toast.LENGTH_LONG).show();
Api.applySavedIptablesRules(context, false);//应用防火墙规则
Toast.makeText(context, "Wall rules have been lauched", Toast.LENGTH_LONG).show();
}
}
public void writefile(String str,String path )
{
File file;
try {
//创建文件
file = new File(path);
file.createNewFile();
//打开文件file的OutputStream
out = new FileOutputStream(file);
String infoToWrite = str;
//将字符串转换成byte数组写入文件
out.write(infoToWrite.getBytes());
//关闭文件file的OutputStream
out.close();
} catch (IOException e) {
//将出错信息打印到Logcat
}
防火墙
最新推荐文章于 2024-10-10 20:50:56 发布
