[英]Android application prevents device from locking screen and sleeping
現在,由Android Studio創建的我的Android應用程序無意間阻止了我的Galaxy設備鎖定屏幕和進入睡眠狀態。 請求的權限如下:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
之前我包含了許可
<!--<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>-->
但現在此行已被注釋。 現在僅請求INTERNET
和ACCESS_NETWORK_STATE
權限。 我試圖從設備上明確刪除(卸載)我的應用程序,然后再次安裝,但是該應用程序(在啟動並處於活動狀態時)不允許設備進入睡眠狀態。 當其他應用程序處於活動狀態(我的應用程序已啟動但處於非活動狀態)時,設備將在規定的時間內進入睡眠狀態。 該應用程序使用PendingIntent
, Broadcast
和AlarmManager
類,但是即使沒有調用這些類的方法,設備也不會休眠。 不使用 WakeLock
類。
AndroidManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="spectorsky.timer">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>-->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="spectorsky.timer.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="MyAlarmReceiver" />
</application>
這是接收器類:
public class MyAlarmReceiver extends BroadcastReceiver {
public MyAlarmReceiver() {
super();
}
public void onReceive(Context context, Intent intent)
{
int channelNumber=intent.getIntExtra("channelNumber",13);
String ipAddress=intent.getStringExtra("ipAddress");
int nChannel=intent.getIntExtra("nChannel",13);
intent.getParcelableExtra("messenger");
new TVTimerAsync(ipAddress,nChannel,m, context).execute(MainActivity.digitReader(channelNumber));
}
}
這是調用BroadCast的代碼:
MyIntent myIntentAlarm;
int myIntentId=0;
AlarmManager myAlarmManager;
...................
myAlarmManager.set(AlarmManager.RTC_WAKEUP, d.getTime(), PendingIntent.getBroadcast(MainActivity.this, myIntentId++,
myIntentAlarm, PendingIntent.FLAG_ONE_SHOT));
預先感謝您的任何想法。
PS有很多關於這種問題的文章,但是我找不到類似我的情況的東西。
我已經清理了項目中的幾乎所有內容:應用程序在刪除ListView
定義中的android:keepScreenOn
屬性后恢復了睡眠能力:
<ListView
android:id="@+id/listIntents"
android:layout_width="wrap_content"
android:layout_weight="1"
android:choiceMode="multipleChoice"
android:focusable="false"
android:focusableInTouchMode="false"
android:keepScreenOn="true"
android:scrollIndicators="right"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideInset"
android:textFilterEnabled="false"
android:layout_height="match_parent"
android:text="@string/deleteChosen">
</ListView>
我確實希望此屬性使列表能夠保留在其他控件的前面,並且永遠不會被隱藏。 但是,含義似乎有很大不同:“保留在屏幕上”表示屏幕始終處於打開狀態。
感謝大家的幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.