【问题标题】:how to make my app open when the screen turns on in android如何在android中打开屏幕时打开我的应用程序
【发布时间】:2013-07-30 19:15:18
【问题描述】:

当我打开我的屏幕时,我想让我的应用程序打开。 这是密码应用程序,我希望每次屏幕打开应用程序时都会询问密码。

我编写了应用程序所需的所有代码,但它无法正常工作并且应用程序无法打开。 我使用了 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
   }
}

如果有人能帮助我,我会很高兴,如果有人也能告诉我我是如何取消主页按钮的,我将非常感激:)

【问题讨论】:

  • 查看我的回答 here 以禁用主页按钮并从 BroadcastReceiver 开始活动。
  • 虽然我认为可能有更好的方法来实现你正在寻找的东西。

标签: android broadcastreceiver


【解决方案1】:

其他 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 activity over default lock screen


进一步的 SO 帖子建议您需要执行类似的操作,以便您可以使用应用程序解锁手机;

权限:&lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt;

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

Lock the android device programmatically(有人说该方法已过时,但docs 似乎不同意)

【讨论】:

  • 请记住,如果您使用此方法,如果用户有密码(pin、pattern 等),它仍然不起作用,因为您无法使用上面的标志绕过它。
  • 所以在输入密码后它会起作用吗?还是只是打不开?
  • 添加&lt;hr/&gt;下的第二部分,涵盖绕过密码的方法。
猜你喜欢
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多