Android 11 - creating app's directory as a shared folder under Storage root - android-11

We need to create our app's directory as a shared one under Internal storage root so that all files/images received and downloaded through our app can be viewed using any File manager, Photo gallery etc. Till Android 10, we were able to do that but in Android 11, when we use getExternalFilesDir to know the root and create app's base directory, it is not visible from a File Manager.
//This is not visible from File Manager
File rootAppDir = context.getExternalFilesDir(null);
//This points to some other location, cannot see base directory of other apps under this
File rootStorageDir = Environment.getStorageDirectory();
We see many other apps that have created their folders under Internal Storage, such as Signal, Telegram etc. Please let us know what we might be doing wrong and how to create our app's base directory under Internal Storage root. Appreciate your help.

We did as recommended by #CommonsWare - set android:requestLegacyExternalStorage="true" in Manifest and (important) marked down targetSdkVersion from 30 to 29. That worked.

Related

Documents and Music folder -> Windows Defender Ransomware protection breaking my app

So it looks like Windows 10 Ransomware has broken my app (StationRipper). It's a C++/MFC app, but it looks like it would break any app that is doing what StationRipper is doing.
My high-level question:
My app needs to write files (e.g., mp3's) as it records them. Is there actually a sensible place do this to (like, say, the Music folder) if Ransomware protection is on, or am I stuck just creating an arbitrary folder someplace? My app is doing the recording behind the scenes, so the user can't choose the dir for each file.
Details:
My app records music files. A very long time ago (like, in 2002) it wrote it to the users "Music" directory. That worked fine, but now I'm seeing a problem - I'm getting the error code for "The system cannot find the file specified." on CreatedDirectory for my app (which was really fun to track down, as that error code isn't listed as an error that CreateDirectory to return), and when I try to write any file to that directory if I manually create it via file explorer.
I finally tried running mkdir, and to create a file in that dir, outside of my app... the same thing happens.
I turned off Ransomware protection in Windows Defender... and it now works from my app.
It looks like I have to use something like the file picker to save to that dir? Which, as I said, won't work as the user isn't involved after they start recording.
I can't just tell my users to turn Ransomware protection off to use my app, but I would prefer to put the music files in their Music folder...
Any suggestions?
Additional info requested in comments:
TCHAR szDocPath[MAX_PATH];
szDocPath[0] = 0;
if (::SHGetSpecialFolderPath(NULL, szDocPath, CSIDL_PERSONAL, FALSE))
{
_tcscat(szDocPath, "\\StationRipper");
DWORD m_dwLastError = ::GetLastError();
BOOL bResult = CreateDirectory(szDocPath, NULL);
m_dwLastError = ::GetLastError();
}
Running the above with Ransomware protection on results in a zero. With it off returns a 1 (and the directory is created).
(note: SHGetSpecialFolderPath is not supported, but its modern equivalent, SHGetKnownFolderPath has the same issue)
Rather than asking users to disable Ransomware Protection entirely, you can ask them to whitelist your application. See the Whitelist apps with Controlled folder access section of this article (the official documentation is somewhat lacking).

reason = "The model used to open the store is incompatible with the one used to create the store"

i am creating os x app with core data. when i am modify the model. the error occurred that is showed in the image. the reason shown is "The model used to open the store is incompatible with the one used to create the store"; how to fix this error. this same error i fixed by clearing the simulator in iOS app . how to fix this in os x app.
enter image description here
If you look at the code that sets up your persistentStoreCoordinator, it should tell you where the storage for your objects is located and the file name. (The default location from the Apple template is provided by the applicationDocumentsDirectory method inside the app delegate.)
The usual location for the data store of a non-document-based Core Data application is in ~/Library/Application/Support/com.mydomain.myapp/CocoaAppCD.storedata.
Rename or delete this file (depending on whether its contents are disposable).
Re-launching your application will recreate the file with no data and you can start re-populating it according to your new model.
With production versions of your application, a model change would require a formal lightweight or heavy migration to preserve the user's data.
As a convenience, on startup I print out the location of the database to the console as follows:
// Get / print location of database for use in testing / debugging
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let path = paths[0] + "/LocalStore.sqlite"
print(path.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines))
Besides being easy to see, I can just select/copy/past this to use in sqliteBrowser.
Choose Finder and go to Library from Go by clicking option button on keyboard. then search on library using your app Bundle Identifier. delete the folder with it. then Re-launching your application will recreate the folder with no data and you can start re-populating it according to your new model.

Issues while converting a windows app to windows service

I created a monitoring utility that checks cpu, ram, drive space stats and emails if the usage goes above set threshold. It works great in the system tray but I realized that the exe will stop when I log out of windows server. That led me to believe that I needed to create a windows service. I would like to use the existing GUI Form to save data to application settings and use those settings in windows service. Here are the steps I took so far,
Added a Windows Service class.
Modified the original code to get rid of any interactive items that were related to GUI Form.
Added the code to this class.
Added a Service installer.
Added this code to it-->
public ProjectInstaller()
{
InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Server Monitoring";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
Change Start up object to Utility.Program.
When I try installing this through installUtil I get this error
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Use
rs\AdminUser\Desktop\Temp\Server' or one of its dependencies. The system cannot
find the file specified..
Thanks!
If you are saving these application settings into a file that is in the same directory as the Windows service, that is going to be your problem. All Windows Services are run in the C:/Windows directory (or a sub-directory in there) so when you access files you will need to do one of two things:
Change the executing directory
You can change the 'current directory' for the executing app back to the folder that contains the exe with the following line of code:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
This will make all relative files become relative to the executable location once again.
Make all file request full paths
This one is easier for some files than others. System files are the hardest. So if you are trying to get to a .config file, that's going to be a nightmare.

Unable to download at this time; enterprise build/ad hoc distribution

So I have a very weird problem. Trying to deploy the once click deployment using the enterprise code signing thing.
I have it uploaded on the server and I go to the link in safari, when I open it on the iPhone it gives me unable to download, application cannot be installed at this time. However, when I tried it on my iPad (iPhone app running on iPad), it works just fine. Why is this?
Your problem is one of 2 things.
The xml in your .plist that goes with the app has incorrect values or you are using a non enterprise distribution certificate. Make sure you have a current certificate and when building select that cert. Also make sure the xml in your plist is correct.
Note a fields you enter when building the app ( icon, target host, etc. ) are not necessary to enter all the time. ( I just type the letter a into each field ) I copied the original plist and changed the values manually. I deploy the file to a temp folder and only copy the .ipa to by IIS virtual folder.

SDF file always being created as read only after installation on Windows Mobile

My windows mobile app has a local database file (database.sdf). The file that is created when the user installs the CAB file in their device. The installation works fine but when I try to open the SDF with Query Analyzer or when the app tries to access the database I get a message.
"Access to the database file is not allowed" (25039)
When I checked the permissions using Windows Explorer (the device is docked), the file is marked Read Only. If remove the Read Only checkbox everything works fine, I can open, edit and add records to the database.
How I can make the file not Read Only by default?
You could verify the attribute programmatically during start-up of your application. In C#/.netcf it would be:
if (File.GetAttributes(path) & FileAttributes.ReadOnly == FileAttributes.ReadOnly)
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
In addition to the answer provided by yms, I would try to figure out why the file is being created as ready-only in the first place.
Is it created via some custom installer dll you added to the installation process? Or is it packaged up into the .CAB file via cabwiz or an installer project in VS?
If it's the former, check the source code of that installer library.
If it's the latter, check the source files. If you include the SDF in your Visual Studio project and have the project checked into some type of source control, it's likely that while it's checked into the source repository it's read-only on disk when it get's packaged up into the .CAB.
I know this is old, but if Andrew is actually using the .netcf, it doesn't have File.GetAttributes. Instead he should use
FileInfo info = new FileInfo(pathToFile)
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
info.Attributes &=~ FileAttributes.ReadOnly;

Resources