Unauthorized access while copying files onto USB via OTG Xamarin Android - usb-otg

I am writing a code to paste files onto the USB Sandisk pen drive connected to my android KitKat device using an OTG cable.
I am using the following code snippet.
Using the following code I get a popup asking permission and on allowing it the mUsbManager.HasPermission(device); returns true, but while i copy the file I get an Unauthorized access exception.
I have set the WRITE_EXTERNAL_STORAGE permission.
//Code Snippet
UsbManager manager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
var deviceList = manager.DeviceList;
IEnumerable deviceIterator = deviceList.Values.AsEnumerable();
if (deviceIterator.Count() > 0)
{
var device = deviceIterator.ElementAt(0);
ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
var mPermissionIntent = PendingIntent.GetBroadcast(_mainActivity.ApplicationContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
UsbManager mUsbManager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
mUsbManager.RequestPermission(device, mPermissionIntent);
bool perm = mUsbManager.HasPermission(device);
if (perm)
{
string FileNameSource = "/storage/emulated/0/FileNotPresent.txt";
string FileNameDestination = "/storage/2A85-5687/FileNotPresent.txt";
File.Copy(FileNameSource, FileNameDestination);
}
}
Second question how can i get the path for the connected USB that as of now i have hard coded into the FileNameDestination variable.
A sample code snippet will really be helpful. Thanks.

Related

How to detect DVD drive name with nodejs?

i create an cross platform electron application for playing video from dvd (in offline mode).
when user inserted DVD in the driver , the xml file (list of videos url and details) should load from DVD.
so for video url i need access to dvd driver name.
<video src="file:/video/video.mp4">
*file:/ should be dvd drive name.
there was a npm package but not working
https://www.npmjs.com/package/drivelist
there was another package return system volume as dvd-rom.
https://www.npmjs.com/package/diskinfo
this code return the dvd drive name, but i'm not sure its good idea or not.
var d = require('diskinfo');
var cddisk;
d.getDrives(function (err, aDrives) {
for (var i = 0; i < aDrives.length; i++) {
if (aDrives[i].available == 0) {
cddisk = aDrives[i].mounted;
console.log(cddisk);
}
}
});
also this package not supported in mac.

Windows 10 IOT Network File

i'm trying to access videos from local network with Windows 10 IOT Core.
I Have added Permissions:
internetClient
privateNetworkClientServer
internetClientServer
enterpriseAuthentication
videosLibrary
removableStorage
remoteSystem
FileTypeAssociation are set in manifest.
folderPicker.PickSingleFolderAsync() return null:
var folderPicker = new FolderPicker();
//folderPicker.SuggestedStartLocation = PickerLocationId.HomeGroup;
folderPicker.FileTypeFilter.Add(".avi");
folderPicker.FileTypeFilter.Add(".mp4");
folderPicker.FileTypeFilter.Add(".mpg");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
var files = await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByTitle);
this throw a fileNotFountException:
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(#"\\192.168.0.10\videos\TestVideos\");
StorageFile file = await folder.GetFileAsync("video1.avi");
the codes work in debug x86 (windows 10 App), but dont on the ARM(RT) (Windows 10 IOT)
As i can understand, they are some limitation for security. Its there a way to disable this security? Or is it possible to write a library to access files?
tanks!
windows IOT version : 10.0.14393.448
Hardware: Raspberry Pi 2 Model B
Network: Ethernet Cable

New websocket on different instance of site

I have a remote control for 4 Devices running on a node server.
Each device has its own page (/1, /2, /3, /4), but they are all generated from the same html/js.
the only difference is the ip for each device, loaded from a json on the server depending on the url path.
This all works, but the problem is: i have 3 obviously wrong IPs entered for testing purposes, and one correct one. Now if i open the correct one, go back to the parent page and open the page of a device with a wrong IP, it is still shown as online and can be controlled.
I understand this like: the socket stays open across the pages and is actually not built new on every site.
how can i make sure that each subpage generates a new socket?
right now, i just have
socket = new io.connect();
in the browser.js,
ioServer.on('connection', function (socket) {
//etc.
}
in the app.js and it works for ONE device.
Am I right to assume that I need some kind of "destroy socket if page is changed"-function?
Thanks for the help
By the looks of it, you only want to instantiate and boot a device when the device's client connects for the first time and emits 'startup'. If this is not the case, I'd probably instantiate and boot each device when the server starts.
Going with the first case, I'd store your devices in a key-value object and reuse them when needed.
var devices = {};
ioServer.on('connection', function (socket) {
var client_ip_address = socket.request.connection.remoteAddress;
console.log("New Connection from: " + client_ip_address);
var device;
socket.on('startup', function (data) {
var deviceId = data.device;
console.log("[INFO] startup: device " + deviceId);
//If this device is already in devices, resuse it
if (deviceId in devices) {
//Get the device from your devices object
device = devices[deviceId];
//Otherwise, create a new device and store it in devices
} else {
device = new HyperDeck(deviceId);
//Store new device in devices object
devices[deviceId] = device;
device.boot();
}
console.log(device.id);
console.log(device.ip);
});
...

bluetooth file transfer in c#

I am writing a bluetooth file transfer from my PC to Samsung galaxy using 32Feet.net
Following is the code,i am getting like:
Internal server error final
On my mobile set i saw file transfer but incomplete and message "remote device disconnected"
I tried to send file directly from my pc and it succeeded but using C# it did not work.
I tried 32Feet.net and some other blogs but could not get through.I read i should do pairing but dont know how to do it.
Please help me out of this.
private void sendFile()
{
SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog();
// dialog.ShowAuthenticated = true;
dialog.ShowRemembered = true;
dialog.ShowUnknown = true;
OpenFileDialog ofd = new OpenFileDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (ofd.ShowDialog() == DialogResult.OK)
{
System.Uri uri = new Uri("obex://" + dialog.SelectedDevice.DeviceAddress + "/" + ofd.FileName);
ObexWebRequest request = new ObexWebRequest(uri);
request.ReadFile(ofd.FileName);
ObexWebResponse response = (ObexWebResponse)request.GetResponse();
MessageBox.Show(response.StatusCode.ToString());
response.Close();
Cursor.Current = Cursors.Default;
}
else
{
MessageBox.Show("File Not Selected");
}
}
else
{
MessageBox.Show("Device Not Selected");
}
}
Pairing is something you do with Bluetooth devices before you transfer files between them. The devices have to know who they are talking to and trust each other.
On Windows XP
http://support.microsoft.com/kb/883259
On Windows Vista, 7, or 8 go to the start menu and start typing "Bluetooth". The entries that pop up should lead you the right direction.

Java Me video player realize error with http - MediaException

I'm using the below code (references from, http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html). It fails at 'realize()', with the javax.microedition.media.MediaException, "Unable to create native player". What is the problem here?
I tried this using both Eclipse and Netbeans. Am I missing some "internet" permissions or using any incorrect encoding, the video is an external 'mpg' test-resource and does work fine when downloaded through a desktop browser.
public void run()
{
String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG";
//Append the GUI to a form
Form form = new Form("Video on java mobile!");
Display display = Display.getDisplay(this);
display.setCurrent(form);
try
{
HttpConnection conn = (HttpConnection)Connector.open(url,
Connector.READ_WRITE);
InputStream is = conn.openInputStream();
Player p = Manager.createPlayer(is,"video/mpeg");
//I tried the below, but that didn't work either
//Player p = Manager.createPlayer(url);
p.realize();
//Get the video controller
VideoControl video = (VideoControl) p.getControl("VideoControl");
if(video != null)
{
//Get a GUI to display the video
Item videoItem = (Item)video.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
form.append(videoItem);
}
//Start the video
p.prefetch();
p.start();
}
catch(Exception e)
{
form.append(url + " Error:" + e.getMessage());
}
}
I've just started with Java, Eclipse, Netbeans. Since, there similar samples found everywhere, I believe I'm missing something very basic. Can someone please help?
The problem here was the video file. Although my source video seemed "mpeg", it wasn't acceptable to the emulator. After searching through a bit, I found a converter and I manually converted some sample mp4 to "mpeg". It finally worked with the same emulator, after I tried to download and play these manually converted files.
One piece of advise if you are new J2ME/JavaME apps (like me), keep playing with the input data sources/formats and the emulators. Switching emulators or the input data-formats is an easy way to identify the not-so-evident problems.

Resources