【发布时间】: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 开始活动。
-
虽然我认为可能有更好的方法来实现你正在寻找的东西。