Recognize internal storage of portable device through MTP in C# - c#

I'm trying to develop winform(C#) application to search file from connected portable device(mobile device) using MTP.
I can get connected or disconnected status from wndproc method using WM_DEVICECHANGE.
But what I really want to develop is to cause an event when internal storage is created (it is able to read on window) after the deivce is connected from MTP.
So I was trying to create wndProc and input the code below in this code "if (m.Msg == UsbAlert.WM_DEVICECHANGE){ ... }"
if (devType == UsbAlert.DBT_DEVTUP_VOLUME)
{
Console.WriteLine("DBT DEVTUP VOLUME");
DEV_BROADCAST_VOLUME vol;
vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
Console.WriteLine(vol.dbcv_unitmask);
}
But it is only can operate portable device such as USB not a mobile phone (android, ios)
There are so many codes for connecting device to windows but not for mobile phone.
Please let me know how can set an event when internal storage is ready to scan on windows.
Can I use WndProc function to develop this or not.
Thank you.

I just solved by myself not using the WM_DEVTUP_VOLUME using wnd_proc fuctions.
This article make me solved the problem below.
How to get MTP device Available Storage & Storage Capacity using C#?
You can get storage voulme using WPD lib from windows.

Related

Defining GattCharacteristic as a Server

I want to fill my variable "selectedCharacteristic" with
GattCharacteristic selectedCharacteristic
selectedCharacteristic = Constants.ResultCharacteristicUuid;
Unfortunately, this doesn't work. It won't convert.
The ResultCharacteristicUuid is from the Microsoft UWP BLE Example.
https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cs/Constants.cs
My program, which has not much to do with the microsoft example (besides the constants.cs),
opens up a BLE Service on start, along with the Result-Characteristic. It acts as an BLE server, nothing more.
So when my BLE Server started, there should be a simple solution to get the device infos and everything GattCharacteristic needs, or not?
The goal is to write to the characteristic as the server, not as a client.
What do I need to get the ResultCharacteristic-Uuid into selectedCharacteristic ?
The UUID should be defined by yourself when you are creating your own service, characteristic. Based on the document- Bluetooth GATT server, you could generate your custom UUID from Visual Studio through Tools -> CreateGuid (use option 5 to get it in the "xxxxxxxx-xxxx-...xxxx" format). This uuid can now be used to declare new local services, characteristics or descriptors.

Initializing Mobile Hotspot using bluetooth C#

I need to create a service that starts a mobile hotspot using bluetooth. I've found the code to create a hotspot service, but this creates a hotspot with the Ethernet adapter.
I've read the documentation and can't find anything to specify bluetooth like in the settings UI.
This is the code to initialize the hotspot with the Ethernet adapter.
var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
var tetheringManager = Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager.CreateFromConnectionProfile(connectionProfile);
The problem with this is that the network is shared through WiFi, and not Bluetooth.
Here are my current connections:
My OS were unfortiunately installed in Norwegian, but the display should look familiar in English.
GetConnectionProfiles returns a IReadOnlyList of ConnectionProfile. You can then try to select a specific profile from the list to operate on, instead of using the default one you have in your snippet.

Detect if game running in android emulator

Is there any way to know the game is running in an emulator application or a real device ?
Some Applications like VirtualXposed are virtual emulator for android devices. Such Applications allow users to install a game / application multiple times on their device with different identifies.
I want to know is there any way to recognize my game / application is running in emulator or a physical device in unity3d ?
something like :
if(isemulator)
{
dosomething();
}
It's not easy to do since there are many emulators out there. The answer from this post says that you can use Build.FINGERPRINT.contains("generic") to do that.
You can port the Java code to C# in Unity with the AndroidJavaClass class and without building Java plugin. Below is the ported version in C#:
public bool IsEmulator()
{
AndroidJavaClass osBuild;
osBuild = new AndroidJavaClass("android.os.Build");
string fingerPrint = osBuild.GetStatic<string>("FINGERPRINT");
return fingerPrint.Contains("generic");
}
To make sure that this covers most emulator, use the android-emulator-detector plugin. This plugin seems to be rigorously tested and detects most emulators. You can use AndroidJavaClass to communicate with it and UnityPlayer.UnitySendMessage to make callback into your Unity code in C#.
Maybe you can look for some emulator specific SystemInfos (Unity Docs SystemInfo) eg. SystemInfo.deviceModel

BarcodeScanner.GetDefaultAsync() is always returning null

I'm trying to create a simple application in UWP for a Zebra device (Model TC700J) running Windows 8, in which I make use of the built in barcode scanner.
From what I've found, there's plenty of Zebra tutorials for accessing the scanner when programming on Android, but none for Windows due to the fact that Microsoft provide their own generic barcode scanner API found in the Windows.Devices.PointOfService namespace.
The code I currently have looks something like this:
BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
claimedScanner = await scanner.ClaimScannerAsync();
}
The problem is that the if statement never evaluates to true as the GetDefaultAsync method always returns null.
Over here there was an answer that seemed to work, stating that it depends where the GetDefaultAsync method is placed. I've tried to put it in all of the suggested places though and to no avail.
There is another method, BarcodeScanner.FromIdAsync() which returns a barcode based on the string representation of that barcode scanner's id sent as a parameter, but I'm not sure that'd be valid here as the barcode scanner is built into the device.
Looking at Zebra's site, TC700J seems to be model number of Windows 10 Mobile IoT Enterprize OS.
And the platform is ARM(Qualcomm snapdragon), not Intel x86/x64.
TC70 / TC75 Touch Computer Series
https://www.zebra.com/us/en/products/mobile-computers/handheld/tc7x-touch-computer-series.html
TC70x Operating System (TC700J) Windows 10 Mobile IoT Enterprise v1.13.02 Release Notes
https://www.zebra.com/us/en/support-downloads/software/release-notes/operating-system/tc70x-operating-system-v1-13-02--release-notes.html
For example, if your Zebra device is old hardware and Windows Phone 8/8.1 is running, Windows Phone does not seem to support Windows.Devices.PointOfService namespace.
It is described in the comment of the following article.
Windows Phone 8.1: Scan Barcodes using Camera
If your Zebra device can update to Windows 10 Mobile IoT Enterprise, please check it after doing it.
If you can update it, you can use the barcode scanner sample for Windows 10.
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BarcodeScanner
If your device is running on Windows 8 for x86, since Windows.Devices.PointOfService namespace is supported from Windows 8.1, you need to change the OS to Windows 8.1/10 if possible.
In that case you can use following, or above(for Windows10) sample.
Barcode scanner sample for Windows 8.1
https://code.msdn.microsoft.com/windowsapps/Barcode-scanner-sample-f39aa411
If you can not update it, please get the software and documentation for using BarcodeScanner from the vendor on Windows (Phone?) 8.
Seems the usage of Async method wasn't quite right.
Try below code:
BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
claimedScanner = await scanner.ClaimScannerAsync();
}
More details:
https://learn.microsoft.com/en-us/dotnet/csharp/async
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx?f=255&MSPPError=-2147217396

AFORGE.net with android phone as ip camera

Story : I've implemented video streaming application using AFORGE.net, in c# from my laptop camera, using TCP protocol.And it worked excellent.I tested the application on multiple pc's using lan cable and it worked good. I've never worked with IP-Cameras but i read this forum ( http://www.aforgenet.com/forum/viewtopic.php?f=4&t=36 ) and it says that every ip-cam needs a source string that is a URL in order to connect with AFORGE.net's MJPEGStream class:
MJPEGStream mpeg = new MJPEGStream();
mpeg.Login = "username";
mpeg.Password = "pass";
mpeg.Source = "http://ip:port/img/mjpeg.cgi";
mpeg.Start();
Problem : Now i want to use my android phone as an ip-camera for video streaming. I've also created an android application that send images continuously to an address using TCP.
All i want to know that if its possible to use android device as ip-camera? And if yes then what source string i should use with MJPEGStream class.?
Thanks in advance for suggestions and guides.

Categories