如何将网络文件夹挂载到 Android 内部文件夹中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21737016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:59:39  来源:igfitidea点击:

How Can I Mount A Network Folder Into An Android Internal Folder?

androidnetworkingbindingsharedmount

提问by Ivan Verges

I want to mount a network shared folder (Ex: \10.0.0.240\Folder) into an Android internal folder (Ex: /mnt/sdcard/MountedFolder), just like the MountManager App does.

我想将网络共享文件夹(例如:\10.0.0.240\Folder)装入 Android 内部文件夹(例如:/mnt/sdcard/MountedFolder),就像 MountManager 应用程序一样。

My question it's: How can i do it, or how can i at least enter to the network folder and see the files on it directly from my app?

我的问题是:我该怎么做,或者我如何至少进入网络文件夹并直接从我的应用程序中查看其中的文件?

I'm working on a Rooted device, so it doesn't matter about permissions.

我正在使用 Rooted 设备,因此权限无关紧要。

回答by Bryon

This is how you do it in Kit Kat from the command line:

这是在 Kit Kat 中从命令行执行此操作的方法:

mount -o username=<user>,password=<pwd>,file_mode=0777,dir_mode=0777 -t cifs //<NAS IP Addr>/<share name> <mount point dir>

E.g.

例如

mount -o username=guest,password=guest,file_mode=0777,dir_mode=0777 -t cifs //192.168.1.254/public /storage/nas/public

Notes:

笔记:

  • Make sure the directory /storage/nas/public exists and you have set appropriate permissions.
  • If you do not use file_mode and dir_mode you will only be able to access the share from root.
  • 确保目录 /storage/nas/public 存在并且您已设置适当的权限。
  • 如果您不使用 file_mode 和 dir_mode,您将只能从 root 访问共享。

回答by Ivan Verges

Well, i found a way to mount a network shared folder into my android device using Xamarin (C#), just as Mount Manager and CIFS manager does;

好吧,我找到了一种使用 Xamarin (C#) 将网络共享文件夹挂载到我的 android 设备的方法,就像挂载管理器和 CIFS 管理器一样;

You need root permissions to make it work because it's a unix command and need especial permisions.

您需要 root 权限才能使其工作,因为它是一个 unix 命令并且需要特殊权限。

The code it's as simple as the next:

代码就像下一个一样简单:

Java.Lang.Runtime proc = Java.Lang.Runtime.GetRuntime();

proc.Exec(new String[] {"su", "-c", "mount -t cifs -o username=USER, " +
    "password=YOURPASS //xxx.xxx.xxx.xxx/SharedFolder /mnt/sdcard/MountPoint"});

In the code above, replace USER with the user name and YOURPASS with the password to access the network folder.

在上面的代码中,将 USER 替换为用户名,将 YOURPASS 替换为访问网络文件夹的密码。

Replace xxx.xxx.xxx.xxx with the server IP.

将 xxx.xxx.xxx.xxx 替换为服务器 IP。

Replace MountPoint with the name of the folder where you want to mount the network folder, you can also replace sdcard with another directory and even the /mnt with another one, but it's most common to mount into the sdcard, this way any app that scans your sd will see the network files as they're on the sd.

将 MountPoint 替换为您要挂载网络文件夹的文件夹的名称,您也可以将 sdcard 替换为另一个目录,甚至将 /mnt 替换为另一个目录,但最常见的是挂载到 sdcard 中,这样任何扫描的应用程序您的 sd 将看到网络文件,因为它们在 sd 上。