2017-02-15 176 views
0

Android Studio創建的Android應用程序現在無意中阻止我的Galaxy設備鎖定屏幕並進入休眠狀態。請求的權限如下:Android應用程序阻止設備鎖定屏幕和睡眠

<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"/>--> 

但現在這條線被註釋掉。現在只需要INTERNETACCESS_NETWORK_STATE權限。我試圖從設備上明確刪除(卸載)我的應用程序並重新安裝,但應用程序(啓動並處於活動狀態)不允許設備休眠。當其他應用程序處於活動狀態時(我的應用程序已啓動但處於非活動狀態),設備會在指定時間內進入休眠狀態 應用程序使用PendingIntent,BroadcastAlarmManager類,但即使未調用這些類的方法,設備也不會休眠。 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)); 
     } 
} 

這裏是代碼調用廣播:

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有很多關於這樣的問題的帖子,但我找不到像我的情況。

+0

請提供您的清單文件,並檢查是否有程序上提到的與喚醒鎖許可相關的任何代碼。 – KDeogharkar

+0

沒有更多的代碼片斷你的應用程序,我們只能猜測你的問題在這裏.. – IIIIIIIIIIIIIIIIIIIIII

+0

已添加AndroidManifest.xml。代碼中可能與喚醒鎖相關的唯一事物是PendingIntent,Broadcast和AlarmManager類。但是,即使我只是啓動應用程序並且沒有執行這些類的方法,設備也無法進入睡眠狀態。我應該提供創建我的主要活動嗎?它有85行... – Spectorsky

回答

0

我已經清理項目中的幾乎一切:應用程序恢復睡眠能力ListView定義刪除android:keepScreenOn屬性之後:

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> 

我確實希望該屬性使列表保持在其他控件之前,並且它永遠不會被隱藏。但是,這個含義看起來很不一樣:'保持屏幕'意味着屏幕始終打開。

感謝大家的幫助

相關問題