簡體   English   中英

如何在Android屏幕打開時使我的應用打開

[英]how to make my app open when the screen turns on in android

當我打開屏幕時,我想打開我的應用程序。 這是密碼應用程序,我希望每次screnn打開應用程序都會詢問密碼。

我編寫了應用程序所需的所有代碼,但無法正常工作,並且無法打開應用程序。 我使用了RECEIVE_BOOT_COMPLETED:

<user-permission android:name="android.intent.category.RECEIVE_BOOT_COMPLETED" />
<application
  ...
   <receiver
      android:name="com.test.receiver"
      android:enabled="true" >
      <intent-filter>
         <action android:name="android.intent.action.SCREEN_ON" />
         <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
   </receiver>
</application>

這是java部分:

public class receiver extends BroadcastReceiver
{
   @Override
   public void onReceive(Context context, Intent intent)
   {
      intent = new Intent(context, MainActivity.class);
      startActivity(intent); // context.startActivity(intent); does not work too
   }
}

如果有人能幫助我,我會很高興,如果有人也能說我,我將如何取消主頁按鈕,我將非常感激:)

其他SO帖子建議您將需要使用此代碼使您的應用顯示在鎖定屏幕上方;

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
    WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

在默認鎖定屏幕上的Android活動


進一步的SO帖子建議您將需要執行以下操作,以便您可以使用應用程序解鎖手機。

權限: <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    mLock = mKeyGuardManager.newKeyguardLock("activity_classname");
    mLock.disableKeyguard();

以編程方式鎖定android設備 (有人說該方法已過時,但文檔似乎不同意)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM