开发者

can an Android service running on its own process access the app's /data/data/<package> folder?

开发者 https://www.devze.com 2023-04-11 01:26 出处:网络
Part of my application, I create an Android Service, which encapsulate a Native code library.The Android Service is running in its own process.

Part of my application, I create an Android Service, which encapsulate a Native code library. The Android Service is running in its own process. I need the Native code from the Android service to access and write in the private data from the installation folder (/data/data/package folder). Is that possible? Looks like the native code is开发者_高级运维 getting a Write Access error.

In the same line, can this Service access the SD Card directory at "/mnt/sdcard/Android/data/ ? It looks also that the native code gets an access error.

Any confirmation will help

thanks eric


For both questions: Yes.

Your Service is part of your application, same process as Activities and other parts of app. It can access app's private folder, correctly determined by:

getPackageManager().getPackageInfo("com.example.app", 0).applicationInfo.dataDir;

Also it can write to SD card, assuming you have permission in manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

You probably wrongly assume that your service runs in different process than rest of app. It's still the same process, native code doesn't make difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号