小编Grz*_*ski的帖子

Android studio:如何强制重新安装(禁用即时运行一次)?

我知道你可以完全禁用即时运行(新的Android 2.0功能).但是我确实喜欢这个功能,除了在某些情况下: - 当对布局文件进行更改时,它通常不会在访问这些资源时获取导致Nullpointer的更改.

有没有办法绕过即时运行?并强制重新安装?

我知道改变AndroidManifest强制这个但这不方便.

android android-studio android-instant-run

18
推荐指数
1
解决办法
3950
查看次数

如何检查android乐器测试中的工具栏标题?

我在YT Advanced Android Espresso上找到了很棒的乐器测试教程.我从那里拿了代码,对我的需求进行了小调整.

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.AllOf.allOf;

...

@Test
public void checkToolbarTitle() {
    String toolbarTitile = getInstrumentation().getTargetContext().getString(R.string.my_bus_stops);
    onView(allOf(isAssignableFrom(TextView.class), withParent(isAssignableFrom(Toolbar.class)))).check(matches(withText(toolbarTitile)));
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它对我不起作用.测试失败:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (is assignable from class: class android.widget.TextView and has parent matching: is assignable from class: class android.widget.Toolbar)
Run Code Online (Sandbox Code Playgroud)

这有什么问题?我该如何以其他方式测试?

java android android-espresso

11
推荐指数
5
解决办法
4773
查看次数

为什么不显示android通知文本?

我已经编写了以下通知代码,我可以看到通知的通知和标题,但文本不可见.我尝试了很多次静态值,但仍然没有得到什么问题.请帮助我,提前谢谢.

private void messagenotification(String msg, String nextid) {


    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("id", nextid  ).apply();

    Intent intent = new Intent(this, NextActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.blue)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.blue))
            .setContentTitle("Chat")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);



    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Run Code Online (Sandbox Code Playgroud)

android

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

如何在android中覆盖sdcard中的文件?

我需要在我的android设备的SD卡中读取一个文件,并将该文件的内容写入已存在的SD卡中的另一个文件中.

这是我在SD卡中的任何位置读取文件的代码.

public String readFromFile(String fileName) {

    String ret = "";
    try {

        File sdcard = Environment.getExternalStorageDirectory();
        //Get the text file
        File file = new File(sdcard, fileName);


        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        if ( bufferedReader != null ) {


            String receiveString = "";
            StringBuilder stringBuilder = new StringBuilder();

            while ( (receiveString = bufferedReader.readLine()) != null ) {
                stringBuilder.append(receiveString);
            }

            ret = stringBuilder.toString();
        }
    }
    catch (FileNotFoundException e) {
        Log.e("login activity", "File not found: " + e.toString());
    } catch (IOException …
Run Code Online (Sandbox Code Playgroud)

android

2
推荐指数
1
解决办法
7975
查看次数

为什么下面代码的输出是Thread[main,5,main]

public class test1 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Thread t = Thread.currentThread();
        System.out.println(t);
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么上面代码的输出是 - Thread[main,5,main] ?请解释

java multithreading program-entry-point void

0
推荐指数
2
解决办法
4400
查看次数