缺少它。我构建了一个Android应用程序,每次设备解锁时都会使用Action_User_Present来启动Android应用程序。
对于ScreenReceiver类,重要的代码如下:
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
if (arg1.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent IntentInitiateApplication;
IntentInitiateApplication = new Intent(arg0, MainActivity.class);
IntentInitiateApplication.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(IntentInitiateApplication);
}
}
}
AndroidManifest.xml包含以下重要代码:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
无论出于何种原因,这都不足以在设备解锁时启动应用程序。我很困惑,因为应用程序仅在两周之前与此代码完美配合,现在由于某种原因它不是。它让我认为它可能是由于设备更新或Android Studio更新,但我已经在2个不同的物理设备上运行此代码,并在2台不同的笔记本电脑上构建应用程序仍然无法正常工作。任何建议将不胜感激!