有一些应用程序可以检测何时从电话/设备管理员中删除它们。我在 Android 开发人员网站上搜索过,但找不到当用户单击电话/设备管理器中应用程序旁边的“勾号”复选框时触发的标志或接收器。
背景:
我有一个类从 延伸而来AccessibilityService。每当窗口更改时,都会调用以下函数,该函数为我提供前台应用程序的应用程序名称。
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
Run Code Online (Sandbox Code Playgroud)
以下是我设置的配置:
@Override
protected void onServiceConnected() {
super.onServiceConnected();
//Configure these here for compatibility with API 13 and below.
AccessibilityServiceInfo config = new AccessibilityServiceInfo();
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
if (Build.VERSION.SDK_INT >= 16) { //Just in case this helps
config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
}
setServiceInfo(config);
}
Run Code Online (Sandbox Code Playgroud)
辅助服务.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_explanation"
android:accessibilityEventTypes="typeWindowStateChanged|typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken|feedbackHaptic|feedbackAudible|feedbackVisual|feedbackGeneric|feedbackAllMask"
android:notificationTimeout="100" android:canRetrieveWindowContent="true" />
Run Code Online (Sandbox Code Playgroud)
问题:
它在一段时间内工作正常,但一两天后突然停止工作。它不调用该onAccessibilityEvent(AccessibilityEvent event)函数。虽然该应用程序的辅助功能已启用,但在窗口更改时仍然不显示应用程序名称。
如果应用程序从睡眠模式恢复,它可能无法工作?我必须在调试版本之上重新安装应用程序,然后它再次开始工作,但持续了多长时间。
问题:如何确保在窗口更改时它始终返回应用程序名称?
我正在写一个单元测试。下面是我的代码。该架构是使用 Dagger2 的 MVVM。我正在调用 LoginViewModel 中的登录函数,该函数通知 getLoginState 函数。我收到的错误是:
错误:
io.mockk.MockKException: no answer found for: Observer(#8).onChanged(Success(data=))
at io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:90)
Run Code Online (Sandbox Code Playgroud)
登录ViewModel类:
fun logIn(phone: String, phoneCode: String) {
loginState.value = Outcome.success("")
}
fun getLoginState(): LiveData<Outcome<String>> = loginState
Run Code Online (Sandbox Code Playgroud)
登录ViewModelTest类:
@RelaxedMockK
var SUT: LoginViewModel? = null
@Mock
var loginInteractor: LoginInteractor? = null
@Mock
var textValidator: TextValidator? = null
@Mock
var textProvider: TextProvider? = null
@Mock
var blinkUserPreferences: BlinkUserPreferences? = null
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()
@RelaxedMockK
var mockObserver: Observer<Outcome<String>>? = null
@Before
fun setUp() { …Run Code Online (Sandbox Code Playgroud) 我有一个粘性的后台服务,必须一直运行.基本上它跟踪时间,它是一个自定义时钟计时器.但是一旦设备进入空闲状态(当电话屏幕关闭时),定时器(后台服务)也会暂停.
即使屏幕关闭,我该怎么做才能使它始终保持运行?
public class TimerService extends Service {
private Context context;
@Override
public IBinder onBind(Intent intent) {
Logger.LogI(TAG, "Service binding");
return null;
}
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
}
Run Code Online (Sandbox Code Playgroud) 我想将SwitchCompat的app:theme属性值更改为其他值(@style/switchColorStyleBlue)。我怎样才能以编程方式做到这一点?(app:theme 基本上改变了切换的颜色)
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:theme="@style/switchColorStylePink"/>
Run Code Online (Sandbox Code Playgroud)
我试过这段代码,但它没有显示适当的结果:
SwitchCompat switchCompat = new SwitchCompat(this);
switchCompat.setId(i);
switchCompat.setSwitchTextAppearance(getApplicationContext(), R.style.switchColorStylePink);
switchCompat.setChecked(false);
containerRelativeLayout.addView(switchCompat);
Run Code Online (Sandbox Code Playgroud)
我想要的是将主题(开关的颜色)从粉红色更改为蓝色,反之亦然。
android ×4
blackberry ×1
device-admin ×1
mockk ×1
performance ×1
pie-chart ×1
service ×1
switchcompat ×1