【发布时间】:2017-01-07 02:16:16
【问题描述】:
当我的手机屏幕打开和关闭时,如何调用我的锁屏应用程序的单个活动(屏幕锁定), 我正在努力但没有达到我的目标。请帮帮我,我累了。我从广播接收器调用活动,但是当应用程序关闭活动不启动时,这只会启动我的应用程序正在运行的活动。 接收器是`
@Override
public void onReceive(Context context, Intent intent) { Toast.makeText(context, "BroadcastReceiver", Toast.LENGTH_SHORT).show();
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Intent lockIntent = new Intent(context, Lockview.class);
lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(lockIntent);
Toast.makeText(context, "Screen is lock", Toast.LENGTH_SHORT).show();
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Toast.makeText(context, "Screen is unlocked", Toast.LENGTH_SHORT).show();
} else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent lockIntent = new Intent(context, Lockview.class);
lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(lockIntent);
Toast.makeText(context, "Screen is book", Toast.LENGTH_SHORT).show();
}`
并且 MAnifest 是 `
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver
android:name=".AEScreenOnOffReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>` and the activity where I trigger the Reciver is ` BroadcastReceiver mybroadcast=new AEScreenOnOffReceiver();
registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_SCREEN_OFF));
registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));` in the oncreate
【问题讨论】:
-
我已经编辑了我的帖子,请帮忙
-
您是否在 mainfest 中添加了这些?
<uses-permission android:name="android.permission.WAKE_LOCK" />和<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> -
是的,我有
-
先生,我看到了,我的问题是当应用程序未运行时我无法启动我的活动。当运行我的广播接收器的应用程序工作时。
标签: android