无法打开 /sys/bus/msm_subsys/devices/subsys0/name:权限被拒绝
Posted
技术标签:
【中文标题】无法打开 /sys/bus/msm_subsys/devices/subsys0/name:权限被拒绝【英文标题】:Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied 【发布时间】:2018-12-14 00:32:08 【问题描述】:这是一个 Xamarin 应用程序。我编辑照片并尝试保存它。对于一些图像,它保存得很好。其他图像屏幕变黑,调试器退出。
我在日志中发现了这个:
12-13 19:35:42.682 E/JavaBinder(31213): !!! FAILED BINDER TRANSACTION !!! (parcel size = 1112628)
Thread finished: <Thread Pool> #2
The thread 0x2 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #3
The thread 0x3 has exited with code 0 (0x0).
Thread started: <Thread Pool> #8
[0:] Java.Lang.RuntimeException: Failure from system ---> android.OS.TransactionTooLargeException: data parcel size 1112628 bytes
--- End of inner exception stack trace ---
Maybe some of the files are just over some file size limit。以下是相关代码:
var pickerIntent = new Intent (this._context, typeof (SavePickerActivity));
pickerIntent.SetFlags (ActivityFlags.NewTask);
pickerIntent.PutExtra("fileName", fileName);
pickerIntent.PutExtra("fileBytes", fileBytes
this._context.StartActivity (pickerIntent); // <-- CRASH!
也许我应该给它一个流而不是一个字节数组?
【问题讨论】:
这看起来是正确的答案,但我可能需要几天才能验证它***.com/a/45149923/3245937 这个错误意味着你的意图太大了。限制约为 1 MB,您已经超过了。 【参考方案1】:我不是说这是答案,但我不确定是否有答案。
无论如何:
1.将文件写入缓存目录
private async Task<string> WriteFileToCacheDirectory(string fileName, byte[] fileBytes)
File outputDir = this._context.CacheDir;
File file = new File(outputDir, fileName);
FileOutputStream fos = new FileOutputStream(file.AbsolutePath);
await fos.WriteAsync(fileBytes);
fos.Flush();
fos.Close();
return file.AbsolutePath;
2。做的意图
var pathToFile = await WriteFileToCacheDirectory(fileName, fileBytes);
var pickerIntent = new Intent(this._context, typeof(SavePickerActivity));
pickerIntent.SetFlags(ActivityFlags.NewTask);
pickerIntent.PutExtra("fileName", fileName);
pickerIntent.PutExtra("path", pathToFile);
this._context.StartActivity(pickerIntent);
...
3.活动开始(在我的情况下,它是我的 SavePickerActivity.cs)
[Activity (ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
[Preserve (AllMembers = true)]
public class SavePickerActivity : Activity
string fileName;
string filePath;
protected override void OnCreate (Bundle savedInstanceState)
base.OnCreate (savedInstanceState);
var fileNameWithExtension = this.Intent.GetStringExtra("fileName");
var fileExtension = Path.GetExtension(fileNameWithExtension);
var mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(fileExtension.Substring(1));
fileName = fileNameWithExtension.Replace(fileExtension, "");
filePath = Intent.GetStringExtra("path");
var intent = new Intent(Intent.ActionCreateDocument);
intent.AddCategory(Intent.CategoryOpenable);
intent.SetType(mimeType);
intent.PutExtra(Intent.ExtraTitle, fileNameWithExtension);
// https://***.com/questions/9080109/android-image-picker-for-local-files-only
// https://***.com/questions/50980397/when-using-intent-actionopendocumenttree-can-you-allow-the-user-to-save-in-a-loc/51011346?noredirect=1#comment89016456_51011346
// https://***.com/questions/51012702/whats-the-correct-way-to-save-a-file-when-using-the-content-sheme/51013020?noredirect=1#comment89020123_51013020 // note that I said it worked here. i said it worked prematurely because i never got it to work completely (even after wasting too much time trying to write a MCW).
// when saving remotely it saves the file with 0 bytes. so only let it save locally.
intent.PutExtra(Intent.ExtraLocalOnly, true);
StartActivityForResult(Intent.CreateChooser(intent, "Select Save Location"), 43);
...
4. OnActivityResult 从缓存目录中读取文件并保存
protected async override void OnActivityResult (int requestCode, [GeneratedEnum] Result resultCode, Intent data)
base.OnActivityResult (requestCode, resultCode, data);
if (resultCode == Result.Canceled && requestCode == 43)
// Notify user file picking was cancelled.
OnDirectoryPickCancelled ();
Finish ();
else
System.Diagnostics.Debug.Write (data.Data);
try
// read the file out of the cache dir
var file = new Java.IO.File(filePath);
var fileLength = (int)file.Length();
byte[] fileBytes = new byte[fileLength];
using (var inputStream = new FileInputStream(filePath))
await inputStream.ReadAsync(fileBytes, 0, fileLength);
// write the file to the path chosen by the user
using (var pFD = ContentResolver.OpenFileDescriptor(data.Data, "w"))
using (var outputSteam = new FileOutputStream(pFD.FileDescriptor))
outputSteam.Write(fileBytes);
...
【讨论】:
以上是关于无法打开 /sys/bus/msm_subsys/devices/subsys0/name:权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章