小编J. *_*Doe的帖子

如何从测试中访问字符串资源?

我在android中有一个项目。我想在junit中测试它。在资源中,strings.xml我有一个名为labels_array. 如何从junit中的测试方法访问(获取)这个字符串数组?

在测试课我有

    @Rule
    public ActivityScenarioRule mActivityRule = new ActivityScenarioRule<>(
            MainActivity.class);
Run Code Online (Sandbox Code Playgroud)


    @Test
    public void fooTest() {
        ActivityScenario scenario = mActivityRule.getScenario();
}
Run Code Online (Sandbox Code Playgroud)

但是如何使用这些规则和方法来从方法内部访问字符串数组fooTest

testing resources junit android

4
推荐指数
1
解决办法
1518
查看次数

我应该将什么“channelId”传递给NotificationCompat.Builder的构造函数?

我正在尝试编写一个简单的通知应用程序。它所做的只是在单击按钮时发出通知。

我根据本教程逐步编写我的应用程序。

我不明白应该将什么通道 ID 传递给构造函数才能使应用程序正常工作。现在应用程序不执行任何操作(它也不会崩溃)。我猜问题出在变量的初始化上NotificationCompat.Builder notifyBuilder。我不知道要传递什么,所以我只是传递了一个任意字符串"0"

我的问题是我应该将什么传递给构造函数NotificationCompat.Builder,它会让应用程序正常工作吗?

这是主要活动:

public class MainActivity extends AppCompatActivity {
    private Button mNotifyButton;
    private static final int NOTIFICATION_ID = 0;
    private static final String NOTIFICATION_ID_STRING = "0";
    private NotificationManager mNotifyManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mNotifyButton = (Button) findViewById(R.id.notificationButton);
    }

    public void sendNotification(View view) {

        mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder notifyBuilder
                =new NotificationCompat.Builder(this, NOTIFICATION_ID_STRING)
                .setContentTitle("You've been notified!")
                .setContentText("This is your notification text.")
                .setSmallIcon(R.drawable.ic_android);
        Notification myNotification = …
Run Code Online (Sandbox Code Playgroud)

android android-notifications

3
推荐指数
1
解决办法
3635
查看次数