How to change permissions on database

anaylor01

Well-Known Member
Licensed User
Longtime User
I was able to use root explorer to go into the settings.db under /data/data/com.android.providers.settings/databases to change the permissions to get access. Now my question is how to I change permissions to the database through code?
 

anaylor01

Well-Known Member
Licensed User
Longtime User
I tried that but chmod does not show up as an option so I guess I am missing something else some where.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I have a warning in Eclipse that says "Type Safety:The method GetMethod(string class...) belongs to the raw type class. Reference to generic type Class <T> should be parameterized.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I have a log file from the program that actually does this. It is using chmod 0777. As you probably already know that I am very new to this. From what I can understand it looks like it does a chmod 0777 on each folder and then finally the settings.db. It looks like there are some other things it is doing but I do not understand it. I am sure you guys can tell exactly whats going on. I know your probably tired of trying to help me with this but I believe this is doable. I highlighted the name of the program that is modifying the settings.db and the chmod 0777. Please if you could take a look and let me know what you think. I would appreciate it. Who knows maybe you'll learn something too.
 

Attachments

  • log3.txt
    11.1 KB · Views: 276
Upvote 0

MikieK

Member
Licensed User
Longtime User
android provider functionality

Hi, I just stumbled on the same hurdle trying to access the media database. I found it easily enough
data/data/com.android.providers.media/databases/external-#card id in hex#.db
, but I do not have permision to read or copy it, yet alone write to it. I'm stumped, because I don't want my app to need superuser permission in order to get a music file name from a database.

Android does offer the functionality to access certain provider databases, but I am definately not clued up enough to write a library to handle this, is anyone interested?

android.provider | Android Developers

I've been using B4A for three weeks and this has been the only major drawback that I have come across so far.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you want to let the user choose a music file then you can use ContentChooser:
B4X:
Sub Process_Globals
   Dim mp As MediaPlayer
End Sub
Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      mp.Initialize
   End If
   Dim cc As ContentChooser
   cc.Initialize("cc")
   cc.Show("audio/*", "Choose audio file")
End Sub

Sub Activity_Resume

End Sub
Sub Activity_Pause(UserClosed As Boolean)

End Sub
Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
   If Success Then
      mp.Load(Dir, FileName)
      mp.Play
   End If
End Sub
 
Upvote 0

MikieK

Member
Licensed User
Longtime User
Thanks again

Hi Erel,
Thanks again for such a quick reply.
I've played around with content chooser already.
The thing is that, what you use to pick the content (eg. the standard audio picker or a file explorer controls what format you get the Filename (a reference to the database, or the actual file path)
In order to produce an accurate next control (that doesn't depend on the current playlist) or get the mp3's details, I ideally would like to get the information from this database:
"data/data/com.android.providers.media/databases/external-#card id in hex#.db" as shown:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'external-30333863.db is my memory cards database yours will be "external-" & cardid 
'I found the value for cardid in "data/data/com.android.music/shared_prefs/Music.xml"
'code for finding cardid is included in this post
If File.Exists("","data/data/com.android.providers.media/databases/external-30333863.db") Then
File.Copy("","data/data/com.android.providers.media/databases/external-30333863.db",File.DirDefaultExternal,"test.db")
End If
End Sub
This returns the exception:
Java.IO.FileNotFound.Exception: data/data/com.android.providers.media/databases/external-30333863.db (Permission Denied)
similarly:
B4X:
Sub Activity_Create(FirstTime As Boolean)
If File.Exists("","data/data/com.android.providers.media/databases/external-30333863.db") Then
File.OpenInput("","data/data/com.android.providers.media/databases/external-30333863.db")
End If
End Sub
returns the same error
and as expected:
B4X:
Sub Activity_Create(FirstTime As Boolean)
If File.Exists("","data/data/com.android.providers.media/databases/external-30333863.db") Then
Dim SQL As SQL
SQL.Initialize ("","data/data/com.android.providers.media/databases/external-30333863.db",False)
End If
End Sub
returns
android.database.sqlite.SQlite.Exception: Unable to Open Database File
I put my issues here because anaylor01 was having similar problems accessing a similar database (however his where settings which are also included in the link below). I believe that a lot of these databases should be readable (even if they are not marked as), I'm pretty sure that there are classes that enable you to get information in java:
Content Providers | Android Developers

I wouldn't even know where to start using the reflections library, as the reason I'm using B4A is java is like Klingon to me.
I've included my project so far if you want to have a look (Its not really relavent, apart from showing how to find the database mentioned. It already has the content chooser implemented if you choose menu/load)
 

Attachments

  • RadioMp3Player.zip
    5.8 KB · Views: 221
Last edited:
Upvote 0

MikieK

Member
Licensed User
Longtime User
Manifest

Im 51% certain that the reason I can't access these files is due to my manifest. Any comments? What would my manifest have to look like in order for me to access these files. Am I barking up the wrong tree?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You are not meant to be able to directly access these databases, that is why their permissions are set to disallow it. Applications are intended to access them via the appropriate ContentProvider as detailed in the links you have previously posted. For example the Phone library Contacts uses a ContentProvider to access the contact data.

I actually have a ContactProvider library written for MediaStore.Files that can get this data but that only works on Android 3.0 or later. I might look at letting it use other ContentProviders so it will work on earlier devices.
 
Upvote 0

MikieK

Member
Licensed User
Longtime User
There is none. Unless you root your device so you can change the permissions you will need to write a library and if you can't do that hope that one comes along someday.
My device is rooted, I don't see how changing my permissions will help me (or anyone else) make a marketable app? Was I completely wrong about my manifest controling what permissions I have?
I actually have a ContactProvider library written for MediaStore.Files that can get this data but that only works on Android 3.0 or later. I might look at letting it use other ContentProviders so it will work on earlier devices.
Please, pretty please, please, please, please?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…