安卓(杂学笔记)

2020-03-23  本文已影响0人  Jesse4023

1.自动执行某个方法:

在onCreate()方法后面添加:

runOnUiThread(new Runnable() {

    @Override

    public void run() {

        button1.performClick();

    }

});

2.屏幕常亮

Oncreat()方法中super下一行加:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

3.设置为启动器

AndroidManifest.xml中添加:(action中添加)

<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />

4.安卓使用mqtt:

a.项目的build.gradle添加:

dependencies {

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'

implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

}

b.AndroidManifest.xml添加 权限 以及 service

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />                                                                                                                                                <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />                                                                                                                                               
<uses-permission android:name="android.permission.WAKE_LOCK" />                              
<service android:name="org.eclipse.paho.android.service.MqttService" />

c.MQTTManager.java

参考:参考链接

5.gradle sync太慢?

build.gradle

buildscript {
            repositories {
                          maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
                          maven { url "https://jitpack.io"}
                           google()
                           //jcenter()
}

.....

.....

allprojects {
                          repositories {
                                    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
                                    google()
                                    //jcenter()
                                          }
}

上一篇下一篇

猜你喜欢

热点阅读