我有Android应用程序项目,在Android Studio中工作.我的应用程序文件在my.package包中我的单元测试在my.package.unittest包中我的espresso测试是在my.package.androidtest包中
在我的一个espresso测试中,我需要使用我在unittest包下的一个类,但我无法做到.
我需要使用的Unittest类位于app/src/test/java文件夹中:
package my.package.unittest;
public class HelperClass {
...
}
Run Code Online (Sandbox Code Playgroud)
我试图使用它的文件是在app/src/androidTest/java文件夹中:
package my.package.androidtest;
import static my.package.unittest.*;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AppTest {
HelperClass.staticMethod();
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:无法解析符号HelperClass
附加信息:
import my.package.unittest.HelperClass;
Run Code Online (Sandbox Code Playgroud)
这本身就给出了"无法解析符号"的错误.
HelperClass在我的Espresso测试中使用我的UnitTests 的正确方法是什么.
我有一个Android应用程序,在xml布局文件中我有这样的东西:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBoxDone"
android:checked="false"
android:clickable="true"
android:onClick="doneCheckBoxClicked" />
Run Code Online (Sandbox Code Playgroud)
然后在我实现的java代码中
public void doneCheckBoxClicked(View v) { ...}
Run Code Online (Sandbox Code Playgroud)
我可以使用类似的方法来改变焦点.在xml中有类似的东西
android:onFocusChanged="editTextFieldFocusChanged"
Run Code Online (Sandbox Code Playgroud)
然后在java代码中:
public void editTextFieldFocusChanged(View v, boolean hasFocus) { ...}
Run Code Online (Sandbox Code Playgroud)
或者没有办法在xml中进行onFocusChange?
在我的 Andoroid 应用程序中,我想让用户使用用户喜欢的任何发送方法(例如电子邮件、Skype、Viber、蓝牙等)发送我的应用程序生成的文件,我正在使用 Intent.ACTION_SEND,如下所示:
File readF = new File(fullFileName);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.some_subject));
intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.some_message_body));
Uri uri = FileProvider.getUriForFile(this, "my.package.fileprovider", readF);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.some_info_message));
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,它成功地通过 Gmail 和蓝牙发送文件。
但是当用户选择Skype 时,文件被发送,但它的名字被改变了
当用户选择Viber 时,不会发送任何内容。
如果我只改变构建 Uri 的方式:
Uri uri = Uri.fromFile(new File("/some/publicly/available/file"));
Run Code Online (Sandbox Code Playgroud)
然后该文件通过 Skype 和 Viber 成功发送,并保留名称。
那么在 Intent 中使用 FileProvider 与直接使用公共文件有什么区别。
还有一个这样的FileProvider失去了灵魂......我一直在研究这个问题超过一天,似乎我错过了一些大事.任何帮助,将不胜感激!
我正在尝试使用FileProvider发送带附件的电子邮件.
我的AndroidManifest.xml的一部分:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="todolistj.todolist.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
file_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="lists_to_send" path="export/"/>
</paths>
Run Code Online (Sandbox Code Playgroud)
创建附件:
String content = "hello world";
File file;
FileOutputStream outputStream;
try {
File dir = context.getExternalFilesDir("export");
if(!dir.exists()) dir.mkdir();
file = new File(dir, "MyCache");
if (file.exists ()) file.delete ();
outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes());
outputStream.close();
return file.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
和Uri的创作:
File readF = new File(fullFileName);
Uri uri = FileProvider.getUriForFile(this, "todolistj.todolist.fileprovider", readF);
Run Code Online (Sandbox Code Playgroud)
在fullFileName …