如何獲取將資產文件夾中的文件複製到/ etc以及通常無法在非根設備上訪問的其他文件夾的應用程序的root訪問權限或權限。獲取root應用程序的Android應用程序的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();
}
}
添加這些also..still不復制文件 – 2012-08-09 13:19:39
如果它是一個外部存儲位置我希望你加入 前<使用許可權的android:NAME =「機器人.permission.WRITE_EXTERNAL_STORAGE「/>在清單中加上在你的catch塊中添加日誌 – 2012-08-09 14:50:35
我在apk中發送文件,這些文件將寫入/ etc和其他系統文件夾。現在? – 2012-08-09 18:11:42