如何为将文件从 assets 文件夹复制到 /etc 和其他通常在非 root 设备上无法访问的文件夹的应用程序获取 root 访问权限或权限。
我编写了以下代码,但事实证明它不会产生任何错误,也不会执行所需的操作。我需要在清单中编辑一些东西吗?
public class CopyFilesFromApkToSystemActivity extends Activity {
/** Called when the activity is first created. */
private static final String FILE1 = "usb_modeswitch.conf";
private static final String FILE2 = "usb_modeswitch";
private static final String FILE3 = "gprs";
private static final String FILE4 = "ip-up";
private static final String FILE5 = "cdma.sh";
private static String PATH1 = "/etc/";
private static String PATH2 = "/system/xbin/";
private static String PATH3 = "/etc/ppp/peers/";
private static String PATH4 = "/etc/ppp/";
private static String PATH5 = "/system/xbin/";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(this, "Copy started", Toast.LENGTH_SHORT).show();
try {
copyfile(FILE1,PATH1);
copyfile(FILE2,PATH2);
copyfile(FILE3,PATH3);
copyfile(FILE4,PATH4);
copyfile(FILE5,PATH5);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void copyfile(String fileName, String pathName) throws IOException {
InputStream mInput = this.getAssets().open(fileName);
String outFileName = fileName + pathName;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0)
{
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
//Toast.makeText(this, fileName + " copied", Toast.LENGTH_SHORT).show();
}
}