[英]Linking Error - No Write Permission
I have a problem with a project I am working on in Android Studio. 我在Android Studio中正在处理的项目有问题。 The goal is to save a basic string into a .csv file then attach that file as an email attachment. 目标是将基本字符串保存到.csv文件中,然后将该文件作为电子邮件附件附加。
I cant write to the file, but I can share the file via FileProvider.getUriForFile. 我无法写入文件,但是可以通过FileProvider.getUriForFile共享文件。
I think the problem has something to do with these two linker error messages I get, the streamsavvy-1
is concerning bc my package name is com.team6.rifflegroup.streamsavvy
我认为问题与我收到的这两个链接器错误消息有关, streamsavvy-1
与BC有关,我的包名称为com.team6.rifflegroup.streamsavvy
11-13 16:20:39.775 10286-10286/com.team6.rifflegroup.streamsavvy E/linker: readlink('') failed: No such file or directory [fd=31]
11-13 16:20:39.775 10286-10286/com.team6.rifflegroup.streamsavvy E/linker: warning: unable to get realpath for the library "/data/app/com.team6.rifflegroup.streamsavvy-1/oat/arm64/base.odex". 11-13 16:20:39.775 10286-10286 / com.team6.rifflegroup.streamsavvy E /链接器:警告:无法获取库“ /data/app/com.team6.rifflegroup.streamsavvy-1/oat/ arm64 / base.odex”。 Will use given name. 将使用给定名称。
I build the file like this 我这样构建文件
File dataPath = new File(this.getFilesDir(), "xml");
File newData = new File(dataPath, FILE_NAME);
I have a paths.xml
file within an xml directory under res that looks like this 我在res下的xml目录中有一个paths.xml
文件,看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="my_files"
path="/"/>
</paths>
my write function looks like this 我的写功能看起来像这样
try {
FileWriter writer = new FileWriter(newData);
writer.append(csv);
writer.flush();
writer.close();
Toast.makeText(this, "SAVED", Toast.LENGTH_SHORT).show();
}catch (IOException e){
e.printStackTrace();
}
My Email intent looks like this 我的电子邮件意图如下所示
Uri contentUri = FileProvider.getUriForFile(this, "com.team6.rifflegroup.streamsavvy.FileProvider", newData);
this.grantUriPermission(getPackageName(), contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("vnd.android.cursor.dir/email");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"myEmail@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, "File Attached");
emailIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
I give permission in my manifest here 我在此处的清单中允许
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".dataLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.team6.rifflegroup.streamsavvy.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths"/>
</provider>
</application>
I feel like this is a problem with the way java builds its projects but I am not very familiar with the process. 我觉得这是java生成项目的方式存在问题,但是我对该过程不太熟悉。 Any help or pointers would be greatly appreciated. 任何帮助或指针将不胜感激。
This is my first time posting here so I am so sorry if my post is out of context or improperly formatted. 这是我第一次在这里发帖,如果我的发帖内容不正确或格式不正确,我将深感抱歉。
Apologize for the long post. 很久很抱歉。 Figured it out. 弄清楚了。
had to declare the .mkdirs()
call (not .mkdir()
) after specifying the file. 指定文件后,必须声明.mkdirs()
调用(而不是.mkdir()
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.