Cannot open file after downloading it using service - android

I am downloading an mp3 file using service and saving it to sdcard/download directory. It is working fine but after downloading I cant open the file.
There is a toast that shows cannot open the file. I thought there was something wrong with the code but when I tried with jpg file it was fine .
This is my code
public int onStartCommand(Intent intent, int flags, int startId) {
urls=intent.getExtras().get("URL").toString();
DownloadManager.Request request=new DownloadManager.Request(Uri.parse(urls));
request.setTitle("Notification").setDescription("song");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(getApplicationContext(),directory,"downloadedSong.mp3");
FilePermission filePermission=new FilePermission(directory,"read");
PermissionCollection collection=filePermission.newPermissionCollection();
collection.add(filePermission);
FilePermission filePermission1=new FilePermission(directory,"write");
collection=filePermission1.newPermissionCollection();
collection.add(filePermission1);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
return START_STICKY;
Can anybody help me please?
-20 13:46:15.533 1435-1463/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq
java.io.FileNotFoundException: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelCpuSpeedReader.readDelta(KernelCpuSpeedReader.java:49)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8002)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileInputStream.<init>(FileInputStream.java:76) 
at java.io.FileInputStream.<init>(FileInputStream.java:103) 
at java.io.FileReader.<init>(FileReader.java:66) 
at com.android.internal.os.KernelCpuSpeedReader.readDelta(KernelCpuSpeedReader.java:49) 
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8002) 
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366) 
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.os.HandlerThread.run(HandlerThread.java:61) 
at com.android.server.ServiceThread.run(ServiceThread.java:46) 
09-20 13:46:15.534 1435-1463/system_process E/KernelUidCpuTimeReader: Failed to read uid_cputime
java.io.FileNotFoundException: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileInputStream.<init>(FileInputStream.java:76) 
at java.io.FileInputStream.<init>(FileInputStream.java:103) 
at java.io.FileReader.<init>(FileReader.java:66) 
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71) 
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031) 
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366) 
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.os.HandlerThread.run(HandlerThread.java:61) 
at com.android.server.ServiceThread.run(ServiceThread.java:46) 
09-20 13:46:15.534 1435-1463/system_process E/KernelWakelockReader: neither /proc/wakelocks nor /d/wakeup_sources exists

Try to add this: request.setMimeType("audio/MP3");

Related

Unable to save file in internal directory

I a trying to create folder in internal storage in android and want to add files in that folder but app is crashing below is logcat:
11-29 19:40:02.241 23675-23675/com.app.papers E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.papers, PID: 23675
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: java.io.FileNotFoundException: /storage/emulated/0/Papers: open failed: EISDIR (Is a directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
at com.app.papers.PickImage$b.onClick(SourceFile:81)
at android.view.View.performClick(View.java:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
Below is my code:
val document: PdfDocument = PdfDocument()
val pageInfo: PdfDocument.PageInfo? = bitmap?.width?.let { it1 ->
bitmap?.height?.let { it2 ->
PdfDocument.PageInfo.Builder(
it1,
it2, 1).create()
}
}
val page: PdfDocument.Page = document.startPage(pageInfo)
val canvas: Canvas = page.canvas
bitmap?.let { it1 -> canvas.drawBitmap(it1, 0f, 0f, null) }
document.finishPage(page)
val mediaStorageDir = File(Environment.getExternalStorageDirectory(), "Papers")
if (mediaStorageDir.exists()) {
document.writeTo( FileOutputStream(mediaStorageDir))
document.close()
}
What I am doing wrong?
I a trying to create folder in internal storage in android
FWIW, your code is set up for external storage.
Someone please let me know what I am doing wrong any help would be appreciated.
Papers/ appears to exist and is a directory. writeTo() takes a file, not a directory. Try something like:
val mediaStorageDir = File(Environment.getExternalStorageDirectory(), "Papers")
if (mediaStorageDir.exists()) {
val pdfFile = File(mediaStorageDir, "something.pdf")
document.writeTo( FileOutputStream(pdfFile))
document.close()
}

How to write on external memory card in android

I have two different memory locations in android. One is the internal memory location called the external sd card and the other one is the removable memory card.
I have got the read and write permissions in the manifest.
I am also checking its availability.
I have also added android:requestLegacyExternalStorage="true"
My problem is that I am not able to write to this removable media. When I try to write I get this error.
2020-06-06 20:54:13.334 29148-29148/com.test.debug I/OMD::SDCard: /storage/8E14-3919 is removable external storage
2020-06-06 20:54:13.332 29148-29148/com.test.debug W/sdatabase.debug: type=1400 audit(0.0:8919357): avc: granted { read open } for pid=29148 path="/mnt/media_rw/8E14-3919" dev="mmcblk1p1" ino=1 scontext=u:r:untrusted_app:s0:c74,c258,c512,c768 tcontext=u:object_r:vfat:s0 tclass=dir
2020-06-06 20:54:13.336 29148-29148/com.test.debug W/System.err: java.io.FileNotFoundException: /storage/8E14-3919/freebookslibrary.db: open failed: EACCES (Permission denied)
2020-06-06 20:54:13.336 29148-29148/com.test.debug W/System.err: at libcore.io.IoBridge.open(IoBridge.java:496)
2020-06-06 20:54:13.336 29148-29148/com.test.debug W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
2020-06-06 20:54:13.336 29148-29148/com.test.debug W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:125)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.khan.mybookslibrary.BackUpExternal.exportDatabase(BackUpExternal.java:145)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.khan.mybookslibrary.BackUpExternal.access$100(BackUpExternal.java:57)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.khan.mybookslibrary.BackUpExternal$4.onClick(BackUpExternal.java:115)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:177)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at android.os.Looper.loop(Looper.java:213)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at android.app.ActivityThread.main(ActivityThread.java:8147)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
2020-06-06 20:54:13.337 29148-29148/com.test.debug W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at libcore.io.Linux.open(Native Method)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8015)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: at libcore.io.IoBridge.open(IoBridge.java:482)
2020-06-06 20:54:13.338 29148-29148/com.test.debug W/System.err: ... 12 more
2020-06-06 20:54:13.406 29148-29212/com.test.debug W/libEGL: EGLNativeWindowType 0x6f62540b90 disconnect failed
> The code with which am trying to achieve is as follows:
private void exportDatabase(String fileName) {
final File dbFile = context.getDatabasePath(DATABASE_NAME);//existing database file path
SDCard sdc = new SDCard();
File file = sdc.findSdCardPath(context);
FileChannel source = null;
FileChannel destination = null;
if(file!= null){
String backUpPath = file.getAbsolutePath() + "/" + fileName + ".db";
try {
source = new FileInputStream(dbFile).getChannel();
destination = new FileOutputStream(backUpPath).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
alert(context.getResources().getString(R.string.Database_exported_external));
} catch (IOException e) {
e.printStackTrace();
alert(context.getResources().getString(R.string.Failed_export_database_external));
}
}
else
return;
}
I need a solution to this problem

Android Mkdir Eacces Permission Denied

I need to help for mkdir failed: EACCES (Permission denied)
My build setting;
minSdkVersion 15 - targetSdkVersion 19 - compileSdkVersion 25 -
buildToolsVersion "25.0.0"
I use Android Studio 2.3
Debug Device : Samsung J1 (SM-J200F) Android 5.1.1 Android Security Patch Level 2016-12-01
and
Sony Xperia Z5 (E6603) Android 7.0 Android Security Patch Level 2016-12-01
But Google Play APK version is working
Android Manifest;
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Debug Log;
Line 124 : `FileOutputStream out = new FileOutputStream(file);`
`03-23 10:59:06.096 24568-24788/com.myAppName I/System.out: AsyncTask #1 calls detatch()
03-23 10:59:06.106 24568-24568/com.myAppName W/System.err: mkdir failed: EACCES (Permission denied) : /storage/emulated/0/MyAppName
03-23 10:59:06.106 24568-24568/com.myAppName D/Failed: Open
03-23 10:59:06.106 24568-24568/com.myAppName W/System.err: java.io.FileNotFoundException: /storage/emulated/0/MyAppName/MyAppName-6662.jpg: open failed: ENOENT (No such file or directory)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at libcore.io.IoBridge.open(IoBridge.java:456)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at com.myAppName.helper.FileDownloadHelper.SaveImage(FileDownloadHelper.java:124)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at com.myAppName.helper.FileDownloadHelper.onPostExecute(FileDownloadHelper.java:59)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at com.myAppName.helper.FileDownloadHelper.onPostExecute(FileDownloadHelper.java:27)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.os.AsyncTask.finish(AsyncTask.java:636)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.os.AsyncTask.access$500(AsyncTask.java:177)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.os.Looper.loop(Looper.java:145)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6946)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at libcore.io.Posix.open(Native Method)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: at libcore.io.IoBridge.open(IoBridge.java:442)
03-23 10:59:06.111 24568-24568/com.myAppName W/System.err: ... 15 more`
My save function;
private Bitmap SaveImage(Bitmap result) {
String filename = "";
File instaFolder = new File(Environment.getExternalStorageDirectory().toString()
+ "/" + Constants.FOLDER_NAME);
if (!instaFolder.exists())
instaFolder.mkdir();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
filename = Constants.FOLDER_NAME + "-" + n + ".jpg";
file = new File(instaFolder, filename);
if (file.exists()) file.delete();
_mImageUrl = file.getPath();
try {
FileOutputStream out = new FileOutputStream(file);
result.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
Try this:
check if mkdir() returns success or not..and remove .toString()
File folder = new File(Environment.getExternalStorageDirectory() + "/" + Constants.FOLDER_NAME);
boolean success = true;
if (!folder.exists()) {
success = folder.mkdir();
}
if (success) {
Log.d("Success","Open");
// Do work on success
} else {
Log.d("Failed","Open");
// Do work else on failure
}

My App Crashes when I set wallpaper

I have started learning Android this week and wanted to set a background in my main activity , but the moment I set wallpaper my app crashes . This is my logcat output.
10-19 20:44:13.775 12519-12519/com.example.root.newboston E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.root.newboston, PID: 12519
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.newboston/com.example.root.newboston.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.root.newboston.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.root.newboston.MainActivity.onCreate(MainActivity.java:18) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.root.newboston.MainActivity.onCreate(MainActivity.java:18) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 66355212 byte allocation with 1048576 free bytes and 63MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.view.View.<init>(View.java:3948)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
at android.widget.LinearLayout.<init>(LinearLayout.java:199)
at android.widget.LinearLayout.<init>(LinearLayout.java:195)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.root.newboston.MainActivity.onCreate(MainActivity.java:18) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
10-19 20:45:57.468 271-607/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2efcbe0
10-19 20:50:45.380 271-291/system_process E/BluetoothAdapter: Bluetooth binder is null
10-19 20:50:45.396 271-291/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq
java.io.FileNotFoundException: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelCpuSpeedReader.readDelta(KernelCpuSpeedReader.java:49)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8003)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1364)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
at com.android.server.ServiceThread.run(ServiceThread.java:46) 
10-19 20:50:45.400 271-291/system_process E/KernelUidCpuTimeReader: Failed to read uid_cputime
java.io.FileNotFoundException: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8032)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1364)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileInputStream.<init>(FileInputStream.java:76) 
at java.io.FileInputStream.<init>(FileInputStream.java:103) 
at java.io.FileReader.<init>(FileReader.java:66) 
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71) 
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8032) 
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1364) 
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.os.HandlerThread.run(HandlerThread.java:61) 
at com.android.server.ServiceThread.run(ServiceThread.java:46) 
This is my activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/road">
<TextView
android:id="#+id/counterTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Counter"
android:textColor="#ffffff"
android:textSize="45dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/inc_button"
android:id="#+id/incCounter"
android:layout_gravity="center_vertical"
android:onClick="counterFunctionality" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dec_button"
android:id="#+id/decCounter"
android:layout_gravity="center_vertical"
android:onClick="counterFunctionality" />
</LinearLayout>
I read some other posts on stackoverflow , the post mentioned something about insufficient memory to the emulator.
Is it necessary ?
As requested the java code file is
package com.example.root.newboston;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int counter;
TextView counterTV;
Button inc,dec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
counterTV = (TextView)findViewById(R.id.counterTV);
dec = (Button)findViewById(R.id.decCounter);
inc = (Button)findViewById(R.id.incCounter);
inc.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
counter++;
counterTV.setText("Conter : "+counter);
}
});
dec.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
counter--;
counterTV.setText("Conter : "+counter);
}
});
}
public void counterFunctionality(View v){
if(v.getId()==R.id.decCounter){
counter=counter-1;
Log.i("LuD","Value of counter"+counter);
counterTV.setText("Counter : "+counter);
}
else if(v.getId()==R.id.incCounter){
counter=counter+1;
Log.i("LuD","Value of counter"+counter);
counterTV.setText("Counter : "+counter);
}
}
}
One more thing , just now when I changed the background image to one that is smaller in size , (new image size is 16 kB) , earlier file size was 837 kB and now it doesn't crashes in the emulator.
The app crashes in the emulator but I think it should work fine on a real device with decent amount of memory (like 1 GB ).
Am I right ?

Error reading the file from /data directory on rooted android phone. java.io.FileNotFoundException: open failed: EACCES (Permission denied)

This is my code where i'm trying to access a file from /data directory on my rooted device. My app is successfully getting root privileges and also, it can access data from other folders like / or /sdcard or /system etc. The problem arises only in the case of /data directory. And, i'm sure such file exists on the file system and getting the correct path. If the file doesn't exist, then it shows a different error. Now, how can i read the file inside /data directory?
try {
File wifiConfFile = new File(Environment.getDataDirectory()+ File.separator + "system" + File.separator + "appops.xml");
if(!wifiConfFile.exists()){
Log.d("FILE", Environment.getDataDirectory()+"/system/appops.xml couldn't be loaded!");
}
fis = new FileInputStream(wifiConfFile);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
wifiDesc.append(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This is the permission block in my android-menifest file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
And, this is from android monitor...
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: java.io.FileNotFoundException: /data/system/appops.xml: open failed: EACCES (Permission denied)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.IoBridge.open(IoBridge.java:456)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:76)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at rizanamic.wifipass.MainActivity.onCreate(MainActivity.java:71)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.Activity.performCreate(Activity.java:5933)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.os.Looper.loop(Looper.java:135)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5229)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at java.lang.reflect.Method.invoke(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.Posix.open(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.IoBridge.open(IoBridge.java:442)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: ... 15 more

Categories

Resources