Does anyone know how to get access to system folders when making a new app? I am trying to create a new Ad Blocking application for windows (Based on AdAway from android) but cannot get permissions to write to C:\Windows\System32\DRIVERS\ETC\HOSTS.
Can anyone help me out super quick?
sandix said:
Does anyone know how to get access to system folders when making a new app? I am trying to create a new Ad Blocking application for windows (Based on AdAway from android) but cannot get permissions to write to C:\Windows\System32\DRIVERS\ETC\HOSTS.
Can anyone help me out super quick?
Click to expand...
Click to collapse
send your code to access that folder + your app CAPABILITIES to make it faster to answer you . .
I think you have to add many Second_Party and First_PARTY capabilities to your app .
ngame said:
send your code to access that folder + your app CAPABILITIES to make it faster to answer you . .
I think you have to add many Second_Party and First_PARTY capabilities to your app .
Click to expand...
Click to collapse
Is that for the AppxManifest.xml file? Where and what do I add?
ngame said:
send your code to access that folder + your app CAPABILITIES to make it faster to answer you . .
I think you have to add many Second_Party and First_PARTY capabilities to your app .
Click to expand...
Click to collapse
I am using this to write to the AppData folder for my app, but can I do something similar to get to the \Windows\System32\DRIVERS\etc folder?
Code:
private async Task WriteToFile(string content)
{
// Get the text data from the textbox.
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(content.ToCharArray());
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Create a new folder name DataFolder.
var dataFolder = await local.CreateFolderAsync("DataFolder",
CreationCollisionOption.OpenIfExists);
// Create a new file named DataFile.txt.
var file = await dataFolder.CreateFileAsync("hosts.txt",
CreationCollisionOption.ReplaceExisting);
// Write the data from the textbox.
using (var s = await file.OpenStreamForWriteAsync())
{
s.Write(fileBytes, 0, fileBytes.Length);
}
}
sandix said:
I am using this to write to the AppData folder for my app, but can I do something similar to get to the \Windows\System32\DRIVERS\etc folder?
Code:
private async Task WriteToFile(string content)
{
// Get the text data from the textbox.
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(content.ToCharArray());
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Create a new folder name DataFolder.
var dataFolder = await local.CreateFolderAsync("DataFolder",
CreationCollisionOption.OpenIfExists);
// Create a new file named DataFile.txt.
var file = await dataFolder.CreateFileAsync("hosts.txt",
CreationCollisionOption.ReplaceExisting);
// Write the data from the textbox.
using (var s = await file.OpenStreamForWriteAsync())
{
s.Write(fileBytes, 0, fileBytes.Length);
}
}
Click to expand...
Click to collapse
You have to use
StorageFileFile.GetFilefromPath("c:\\ window\\syste32\\drivers\\etc\\Hosts");
This will let you access this storage file if you use correct capabilities on wmappmanfest
I assume that the proper capabilities need to be manually entered into that file?
If so what ones do I need? Because a lot of the ones I've tried give me errors (invalid capabilities)
CAN A MOD PLEASE CLOSE THIS THREAD, I WAS ABLE TO FIGURE THIS OUT ON MY OWN.
Thanks!
Related
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
We intend to sell millions worldwide on PlayStore but, for a limited time offer, you can have it for FREE!
Developer Edition
How to Install:
Method 1 (High Complexity)
1) Copy the below code (CTRL+C)
2) Open Notepad++ [INSERT 007 Theme 'Nobody Does is Better' BEFORE POSTING]
3) Paste into a new document (CTRL+V)
4) Click Save button (CTRL+S)
5) Select whichever folder you want
6) Name it Whatever_you_want.VBS
7) Confirm save
Click to expand...
Click to collapse
Method 2 (Medium Complexity)
1) Download The.Dethumber.Pro.zip
2) Extract the content to whichever folder you want
Click to expand...
Click to collapse
OK! You've proceeded the installation process successfully.
Note: you may save the file with other extension different from .VBS but it won't work.
How to execute:
ATTENTION: this can be harmful. Be careful to provide the exact path of your theme.
1) Double click the file you've saved in the installation process
2) When asked, provide the path of your theme.
Click to expand...
Click to collapse
That's it. No more Thumbs.db into your theme files!!!
How to Uninstall:
1) Delete the file
Click to expand...
Click to collapse
Support is granted only when you are executing the EXACT code below,
Click to expand...
Click to collapse
Code:
' *****************************************************
' * By Kdio to you on 2014-01-31 18:30 UTC
' *
' * You may edit this as you wish. I don't care.
' *
' * Removes any trace of Thumbs.db like files (*.db)
' * from a specified path tree
' *
' * input none
' * output congratulations message
' *
' *****************************************************
On Error Resume Next
'**Global Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set filesToDelete = CreateObject("Scripting.Dictionary")
'**Global Variables
Dim bytesSaved, totalFiles
bytesSaved = 0
totalFiles = 0
'**Request and Set Folder to process
strFolderPath = Browse4Folder()
Set objFolder = objFSO.GetFolder(strFolderPath)
'**Process Selected Folder
ShowSubFolders objFolder
'**If found something to delete
If totalFiles > 0 then
' ** Process deletion
For Each dbFile in filesToDelete
objFSO.DeleteFile filesToDelete(dbFile), 1
Next
Wscript.Echo totalFiles & " Thumbs.db file(s) deleted. You've saved " & CInt(bytesSaved/1024) & " KBytes"
Else
Wscript.Echo "Congratulations. Your work is clean already."
End If
'**Clean up
Set objFSO = Nothing
Set filesToDelete = Nothing
'**End
Wscript.Quit
' *****************************************************
' * Recursively Loop Subfolders Processing each one
' *****************************************************
Sub ShowSubFolders(Folder)
On Error Resume Next
ProcessFolder Folder
For Each Subfolder in Folder.SubFolders
ShowSubFolders Subfolder
Next
End Sub
' *****************************************************
' * Process Folder Files
' *****************************************************
Sub ProcessFolder(Folder)
On Error Resume Next
For Each objFile in Folder.files
'** If any "*.db" file is found
If UCase(objFSO.GetExtensionName(objFile.name)) = "DB" Then
'** Accumulate statistics
totalFiles = totalFiles + 1
bytesSaved = bytesSaved + objFile.Size
'** Add File to Delete Collection
filesToDelete.Add totalFiles, objFile.Path
End If
Next
End Sub
' *****************************************************
' * Browse4Folder Function
' *****************************************************
Function Browse4Folder()
'On Error Resume Next
'**Browse For Folder Constants Definitions
Const WINDOW_HANDLE = 0
Const BIF_EDITBOX = &H10
Const BIF_NONEWFOLDER = &H0200
Const BIF_RETURNONLYFSDIRS = &H1
Dim objShell, wshShell
Dim objFolder, objFolderItem
Dim CrLf, msgBoxButtons
CrLf = Chr(13) & Chr(10)
msgBoxButtons = 308 'Yes/No + Critical + Default No
'**Create Objects to run Shell Commands
Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
'**BrowseForFolder Parameters
strPrompt = "Please select the folder to process."
intOptions = BIF_RETURNONLYFSDIRS + BIF_NONEWFOLDER + BIF_EDITBOX
strTargetPath = wshShell.SpecialFolders("C:\")
'** Prompt the user for Folder
Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, 17)
'** If nothing selected, get out
If (objFolder Is Nothing) Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
'** Make sure the user agree! It's harmful anyway.
If Not (MsgBox("Are you sure you want to delete every *.db file from" & CrLf & objFolderItem.Path, msgBoxButtons, "ATTENTION! This can be Harmful!") = 6) Then
Wscript.Quit
End If
'** Set Function Return Value
Browse4Folder = objFolderItem.Path
'** Clean up
Set objFolderItem = Nothing
Set objFolder = Nothing
Set wshShell = Nothing
Set objShell = Nothing
End Function
Click to expand...
Click to collapse
End-User Edition (updated on 2014-02-05)
How to Install:
1) Download The.Dethumber.Pro.END-USER.zip
2) Extract the content to whichever folder you want
Click to expand...
Click to collapse
OK! You've proceeded the installation process successfully.
How to execute:
ATTENTION: this can be harmful. Be careful to provide the exact path of your theme.
1) Double click the VBS file
2) When asked, provide the zip archive file of your theme.
At the end of the cleaning process, the tool (7zip actually) will generate a report regarding that execution into its same directory. It is just a text file and contain all the statistics of the Thumbs.db detected and deleted.
Click to expand...
Click to collapse
That's it. No more Thumbs.db into your theme files!!!
How to Uninstall:
1) Delete the entire folder
Click to expand...
Click to collapse
Click to expand...
Click to collapse
Tiny-little-tool-dev's Request:
.
Dear Customers
As we are trying to improve our sells and don't have anything more useful to do, we do request from you to share with us the logs you've obtained during the use of our product. This way, the data collected with your effort will bring us more and more money!!! Please, share for nothing!!!
SERIOUS CONDITIONAL: logs can only be accepted IF, before posting, you remove any trace of the source zip analysed. This information is useless.
An example of a correct post would be this as @aki-saar competently did or the below.
Code:
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Listing archive: C:\Users\Kdio\Desktop\xxxxx.zip
--
Path = C:\Users\Kdio\Desktop\xxxxx.zip
Type = zip
Physical Size = 8319796
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
------------------- ----- ------------ ------------ ------------------------
0 0 0 files, 0 folders
Click to expand...
Click to collapse
For a more detailed discussion on the matter, you may read the below thread:
[THEMERS][ATTENTION REQUIRED] Minimum Theme Quality Control
Looks great.. can't wait to try it out.
I will keep this too
delete
aki-saar said:
delete
Click to expand...
Click to collapse
HI aki-saar
Good to hear your success with this tool :good:
As those horrible files are automatically created by Windows when you browse your images, it's advisable to run this tool whenever you are getting to release the theme, just before zipping.
Nice regards.
.
thanks for that simple tool.
time ago i found a big theme with a lot thumbs.db... and i deleted one by one.
i ask for this, into respective thread...but no answer...no big deal.
speedyranger said:
thanks for that simple tool.
time ago i found a big theme with a lot thumbs.db... and i deleted one by one.
i ask for this, into respective thread...but no answer...no big deal.
Click to expand...
Click to collapse
Hi speedyranger
Thanks for you words.
I've been experiencing the same reception for the matter as you've did.
Unfortunately I've could determine that YES ... it's a big deal!
See what I've found out there:
ZIP size: 220 Mb
Extracted: 251 Mb
Thumbs.db: 165 files accounting for 168 Mb [ 67% ] !!!!!!
Click to expand...
Click to collapse
This is ridiculous. And the themer was unaware that they are there. Yes! they are still there because yours exact description of the authors behaviour is what almost all of them has.
EDIT: WROST! All these junk are being flashed into users devices that are too unaware of what is happening.
If you wish, more details about this issue can be found in the below thread:
[THEMERS][ATTENTION REQUIRED] Minimum Theme Quality Control
Thank you very much.
.
Kdio said:
Hi speedyranger
Thanks for you words.
I've been experiencing the same reception for the matter as you've did.
Unfortunately I've could determine that YES ... it's a big deal!
See what I've found out there:
This is ridiculous. And the themer was unaware that they are there. Yes! they are still there because yours exact description of the authors behaviour is what almost all of them has.
EDIT: WROST! All these junk are being flashed into users devices that are too unaware of what is happening.
If you wish, more details about this issue can be found in the below thread:
[THEMERS][ATTENTION REQUIRED] Minimum Theme Quality Control
Thank you very much.
.
Click to expand...
Click to collapse
i see and read that thread.
when i write "no big deal", I mean no big deal if i delete all files by my self...up to 100mb.
now i don't remember what's that theme, but when i see the final result i rest like this
speedyranger said:
I mean no big deal if i delete all files by my self.
Click to expand...
Click to collapse
Hi speedyranger
I've just released a END-USER version specially dedicated for you and all other users.
Thanks a lot.
.
Kdio said:
Hi speedyranger
I've just released a END-USER version specially dedicated for you and all other users.
Thanks a lot.
.
Click to expand...
Click to collapse
will be very useful for users . :good:
I think too, my theme zip lost a lot of bits after cleaning,
Thanks again
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Error:
cannot find archive
If log file say like this what mean sir
Or it mean no .db
idiot me
pas2001 said:
7-Zip
Click to expand...
Click to collapse
If you don't mind. Will answer you in the toll tool thread ... ok ?
EDIT: You senile old idiot bastard (ME, MYSELF AND I). He is in the right thread dumb senior!
.
pas2001 said:
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Error:
cannot find archive
If log file say like this what mean sir
Or it mean no .db
Click to expand...
Click to collapse
Pas
I could not replicate the same behaviour you are having.
When you do not select a ZIP file the following window will open:
If the ZIP is informed correctly and there is no evidence of junk inside, you will receive the following message:
And the correspondent log file will look like this:
Code:
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Listing archive: C:\Users\Kdio\Desktop\xxxxx.zip
--
Path = C:\Users\Kdio\Desktop\xxxxx.zip
Type = zip
Physical Size = 8319796
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
------------------- ----- ------------ ------------ ------------------------
0 0 0 files, 0 folders
Can you upload the ZIP you've select so I could try to replicate the error here.
Can't imagine what is causing your behaviour.
.
@pas2001
Just replicated !
Code:
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Error:
cannot find archive
It's my mistake. It's having trouble with paths that contain spaces or special chars.
As you may know its 03:00AM here and WE are not so young.
Will be promptly correcting the tool as soon as I wake up.
Thank you for your support and testing my flaws.
Nice regards.
.
Idiot's Sticky for tomorrow
Long filepath names needs double quotes to be passed to the OS.
.
Kdio said:
Idiot's Sticky for tomorrow
Long filepath names needs double quotes to be passed to the OS.
.
Click to expand...
Click to collapse
HA HA...Dont be worry friend... I just want to see how the smart tool work.
In this case I use the theme of my friend @aki-saar which I almost sure he use your tool to kill the junks already ( from his post on top of this page)
Your tool work correctly and say congratulation to me (sure it should be clean lol) . Only the log have error as you found .
I concern about you more than these junk files...If you sleep on 3 am every night please beware... your body growth will be disturbed and your height will be stop...Warning from DOC.:silly:
pas2001 said:
Dont be worry friend...
Click to expand...
Click to collapse
Hi pas2001 and ALL
Sorry for the delay.
Updated END-USER package is available at OP.
The problem (I've left inside) was that the script could not deal with Long Path Names.
Should work as expected now. Please report any problem.
Nice regards.
.
pas2001 said:
I use the theme of my friend @aki-saar
Click to expand...
Click to collapse
Hi Pas
Sure @aki-saar's theme is DETHUMBED ... He is one of the few aware of the matter AND have 'balls' to look after his own work with the necessary competence.
But I could not find his theme releasing post ... Where do we can delight our eyes with ?
@aki-saar ... don't be shy dude ... Your theme compared to what we had already seen from 'Recognizeds' sure will be light years ahead!
PUBLISH IT !!!
Nice regards.
.
I'll release the new "clean" version in a few days in a German speak forum. Will send u the link
Edit...
Is every *. dB file junk? I found a lot of in a Rom zip.
I am working on a windows phone Runtime app I want to know how can I find if the app is side loaded or it downloaded from Store directly ? Note : I want to prevent application run when it's sideloaded. I want to prevent crack installation of application
ngame said:
I am working on a windows phone Runtime app I want to know how can I find if the app is side loaded or it downloaded from Store directly ? Note : I want to prevent application run when it's sideloaded. I want to prevent crack installation of application
Click to expand...
Click to collapse
Application License file is your solution.
I think it is difficult to implement. If your app is paid then it will be easy to implement.
Can you mention more details is your app is paid or free or anything else more what you want to do ?
I can do it reading the registry value if some debug cap is attached or configuring write access to the installation path(It is available only the app is side-loaded).
djamol said:
Application License file is your solution.
I think it is difficult to implement. If your app is paid then it will be easy to implement.
Can you mention more details is your app is paid or free or anything else more what you want to do ?
I can do it reading the registry value if some debug cap is attached or configuring write access to the installation path(It is available only the app is side-loaded).
Click to expand...
Click to collapse
It will be a paid app .
in C# you know for example if you type
#if DEbUG
#endif
the code between these two lines will only run when the app running in the debug mode
or
#if Windows_Phone_App
#endif
will only run these lines when app running on a Windows Phone Device .
I'm looking for something like these #if or something else to detect this app isn't installed from store to run this code :
App.Current.Exit();
to prevent using cracked versions and also block these users .
No different between how to detect if the app is sideloaded or not
but the most important thing is this app want to be published on Store so I have to use not restricted APIs and codes .
@ngame
Yeah, forget about that. but you can use file access method for store app.
Is it perfect for you ? It is old method but good one to prevent from side-loading.
Code:
using System.Xml.Linq;
using Microsoft.Phone.Controls;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Phone.Marketplace;
using Microsoft.Phone.Tasks;
using System.Collections.ObjectModel;
using Coding4Fun.Phone.Controls.Data;
public static bool IsHacked()
{
try
{
if (Debugger.IsAttached == true) //then WMAppPRHeader.xml file will be added during AppHub certification only! So this has to be skipped during development.
return false;
//scramble WMAppPRHeader.xml file name to make life a little harder in case of reverse engineering
string fl = "xxx" + "W" + "xxxx" + "M" + "xxxx" + "A" + "xxxx" + "p" + "xxxpxxx" + "PxR" + "xxxxx" + "Hxxxxxxx" + "exxxxxxa" + "xxxx" + "d" + "xxxx" + "xxxxe" + "rxx" + "xxx";
fl = fl.Replace("x", string.Empty) + "." + "x" + "m" + "l";
XDocument doc = XDocument.Load(fl); //is hacked, this file is missing or empty!!!
return false;
}
catch (Exception)
{
MessageBox.Show("This app was pirated and is not safe to use, please download the original one from Marketplace.");
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
//ProcutdID will be changed after APpHub certification, so has to be read from manifest!
marketplaceDetailTask.ContentIdentifier = PhoneHelper.GetAppAttribute("ProductID").Replace("{", string.Empty).Replace("}", string.Empty).Trim(); //download Coding4Fun toolkit for this helper
marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;
marketplaceDetailTask.Show();
return true;
}
}
djamol said:
@ngame
Yeah, forget about that. but you can use file access method for store app.
Is it perfect for you ? It is old method but good one to prevent from side-loading.
Code:
using System.Xml.Linq;
using Microsoft.Phone.Controls;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Phone.Marketplace;
using Microsoft.Phone.Tasks;
using System.Collections.ObjectModel;
using Coding4Fun.Phone.Controls.Data;
public static bool IsHacked()
{
try
{
if (Debugger.IsAttached == true) //then WMAppPRHeader.xml file will be added during AppHub certification only! So this has to be skipped during development.
return false;
//scramble WMAppPRHeader.xml file name to make life a little harder in case of reverse engineering
string fl = "xxx" + "W" + "xxxx" + "M" + "xxxx" + "A" + "xxxx" + "p" + "xxxpxxx" + "PxR" + "xxxxx" + "Hxxxxxxx" + "exxxxxxa" + "xxxx" + "d" + "xxxx" + "xxxxe" + "rxx" + "xxx";
fl = fl.Replace("x", string.Empty) + "." + "x" + "m" + "l";
XDocument doc = XDocument.Load(fl); //is hacked, this file is missing or empty!!!
return false;
}
catch (Exception)
{
MessageBox.Show("This app was pirated and is not safe to use, please download the original one from Marketplace.");
MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
//ProcutdID will be changed after APpHub certification, so has to be read from manifest!
marketplaceDetailTask.ContentIdentifier = PhoneHelper.GetAppAttribute("ProductID").Replace("{", string.Empty).Replace("}", string.Empty).Trim(); //download Coding4Fun toolkit for this helper
marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;
marketplaceDetailTask.Show();
return true;
}
}
Click to expand...
Click to collapse
my code is runtime not a silverlight but I think I got what I have to do from your codes .
I implement a little code in my Program to see what will happen on my Beta release in store .
thanks a lot .
It Works .
write access to Install Directory solved the problem really easy .
Thanks
Alright so I am developing an android app and I am looking for a way to open a pdf file by pushing a button does anyone know how to do this?
I want to be able to push a button on a activity that will open up a pdf file so you can view it
thanks in advance
whitesled said:
Alright so I am developing an android app and I am looking for a way to open a pdf file by pushing a button does anyone know how to do this?
I want to be able to push a button on a activity that will open up a pdf file so you can view it
thanks in advance
Click to expand...
Click to collapse
Hi try this code:
Code:
try {
var f = Ti.Filesystem.getFile('your.pdf');
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: 'application/pdf',
data: f.getNativePath()
}));
}
catch (err) {
var alertDialog = Titanium.UI.createAlertDialog({
title: 'No PDF Viewer',
message: 'We tried to open a PDF but failed. Do you want to search the marketplace for a PDF viewer?',
buttonNames: ['Yes','No'],
cancel: 1
});
alertDialog.show();
alertDialog.addEventListener('click', function(evt) {
if (evt.index == 0) {
Ti.Platform.openURL(linkweb + 'q=pdf');
}
});
}
According to document, trying to use MODE_WORLD_READABLE will crash the module UI with a SecurityException.
I've tried to use a ContentProvider, but unable to get the Context object in handleLoadPackage (Illegal state).
Is there any better way?
Tried to downgrade targetSdkVersion, the app no longer crashes but XSharedPreferences still can't read the file (the preferences file is already world readable)
You can use Remotepreferences (awesome library!). You will need a context however, so it is not suitable for methods in initzigote or where you can't access the context. I think is the only way as of now.
Massi-X said:
You can use Remotepreferences (awesome library!). You will need a context however, so it is not suitable for methods in initzigote or where you can't access the context. I think is the only way as of now.
Click to expand...
Click to collapse
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
And add the following on class level.
Code:
@Override
public void onPause() {
super.onPause();
// Set preferences permissions to be world readable
// Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
final File prefsDir = new File(dataDir, "shared_prefs");
final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (prefsFile.exists()) {
dataDir.setReadable(true, false);
dataDir.setExecutable(true, false);
prefsDir.setReadable(true, false);
prefsDir.setExecutable(true, false);
prefsFile.setReadable(true, false);
prefsFile.setExecutable(true, false);
}
}
This method will work on any sdk :good:
I tested it myself and it is working fine.
Thanks to @PunchUp @pyler
laura almeida said:
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
And add the following on class level.
Code:
@Override
public void onPause() {
super.onPause();
// Set preferences permissions to be world readable
// Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
final File prefsDir = new File(dataDir, "shared_prefs");
final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (prefsFile.exists()) {
dataDir.setReadable(true, false);
dataDir.setExecutable(true, false);
prefsDir.setReadable(true, false);
prefsDir.setExecutable(true, false);
prefsFile.setReadable(true, false);
prefsFile.setExecutable(true, false);
}
}
This method will work on any sdk :good:
I tested it myself and it is working fine.
Thanks to @PunchUp @pyler
Click to expand...
Click to collapse
Yeah but it seems an hacky thing. It will work with any Android? With selinux enabled? On custom ROMs? Surely Remotepreferences complicate things but is the best way (also for previous Android versions) of reading the preferences file. Anyway this can be another solution :good:
EDIT: I also found in marshmallow my apps was randomly failing reading the preferences (no real reason) and Remotepreferences solved the problem.
Massi-X said:
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
And add the following on class level.
Yeah but it seems an hacky thing. It will work with any Android? With selinux enabled? On custom ROMs? Surely Remotepreferences complicate things but is the best way (also for previous Android versions) of reading the preferences file. Anyway this can be another solution :highfive:
Click to expand...
Click to collapse
With any android version - Yes
Will it work with previous android version - Yes
On custom ROMs - Yes
With selinux enabled ? - not tested yet. But I think it works.
laura almeida said:
With any android version - Yes
Will it work with previous android version - Yes
On custom ROMs - Yes
With selinux enabled ? - not tested yet. But I think it works.
Click to expand...
Click to collapse
Previous versions: I was speaking about another thing. See edit. Anyway it's another way, 2 is always better than 1.
Good day. I'm new to android development and I'm trying to develop a simple webview application, picked a nice template and went through the steps and made good progress, I managed to load my site fully and enable javascript, that works as intended, however I'm not able to make the app download anything, I host a few pdf files that should open or download through it, but nothing happens.
I looked at a few answers here and it is to my understanding that I need to specifically add a function for that, could you give me a hand? I have tried multiple different code and tweaking them, but I wasn't able to get it to work, here is my base code:
Code:
package com.logista.test.ui.home
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.app.DownloadManager
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.logista.test.R
class HomeFragment : Fragment() {
private lateinit var homeViewModel: HomeViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
homeViewModel =
ViewModelProvider(this).get(HomeViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_home, container, false)
val myWebView: WebView = root.findViewById(R.id.webview)
myWebView.webViewClient = WebViewClient()
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("https://www.example.org/")
return root
}
}
I believe I should be adding
Code:
import android.app.DownloadManager
And tweak this
Code:
// Set web view download listener
web_view.setDownloadListener(DownloadListener {
url,
userAgent,
contentDescription,
mimetype,
contentLength ->
// Initialize download request
val request = DownloadManager.Request(Uri.parse(url))
// Get the cookie
val cookies = CookieManager.getInstance().getCookie(url)
// Add the download request header
request.addRequestHeader("Cookie",cookies)
request.addRequestHeader("User-Agent",userAgent)
// Set download request description
request.setDescription("Downloading requested file....")
// Set download request mime tytpe
request.setMimeType(mimetype)
// Allow scanning
request.allowScanningByMediaScanner()
// Download request notification setting
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
// Guess the file name
val fileName = URLUtil.guessFileName(url, contentDescription, mimetype)
// Set a destination storage for downloaded file
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
// Set request title
request.setTitle(URLUtil.guessFileName(url, contentDescription, mimetype));
// DownloadManager request more settings
request.setAllowedOverMetered(true)
request.setAllowedOverRoaming(false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
request.setRequiresCharging(false)
request.setRequiresDeviceIdle(false)
}
request.setVisibleInDownloadsUi(true)
// Get the system download service
val dManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
// Finally, request the download to system download service
dManager.enqueue(request)
})
// Load button click listener
button_load.setOnClickListener{
// Load url in a web view
web_view.loadUrl(url)
}
}
Taken from here: https://android--code.blogspot.com/2018/03/android-kotlin-webview-file-download.html
I did the basics, renaming the function accordingly and such, but it gives me quite a few errors when building the app, for instance uri isn't defined, cookiemanager isn't defined, environment isn't defined, build isn't defined, and such, could you give me some guidance?