key-presses屏幕锁定时是否可以在Android中检测到?我希望能够在屏幕关闭时检测到何时按下中央方向键按钮。
假设我的应用程序运行正常,显示 Activity A。然后用户锁定手机。A 尽职尽责地睡觉 ( onPause())。在屏幕关闭的某个时候,我需要向用户展示一些东西。因此,从我的后台代码(服务)中,我为 B 调用 startActivity,并传递以下标志:
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_NEW_TASK
Run Code Online (Sandbox Code Playgroud)
在onCreate()B 中,我添加以下窗口标志
FLAG_SHOW_WHEN_LOCKED
FLAG_TURN_SCREEN_ON
FLAG_DISMISS_KEYGUARD
Run Code Online (Sandbox Code Playgroud)
一切正常 - B 现在出现在键盘锁的顶部。
在稍后的某个时间点,我希望解雇 B,因此从 BI call 中dismiss(),它按预期工作。这就是出错的地方:我现在没有返回锁定屏幕,而是在锁定屏幕上运行 A。
当我解雇 B 时,如何阻止操作系统恢复 A?
谢谢。
我即将向IOS 7的苹果商店提交一个"在播放列表中播放播客"的音频应用.
我正在使用PhoneGap 3.0,除了在锁定屏幕上添加音频标题和相应图像之外,我能够完成所有工作.
如何将歌曲和图像标题添加到锁定屏幕?
我试图了解在Android中覆盖主页按钮功能的方法.我正在做一个LockScreen应用程序和HOME按钮正在解锁设备.
我一直在研究过去3天的方法,我发现的所有解决方案都不是100%有效(主要是由于HOME的性质).
在这三天里,我已经为下面的所有解决方案实施了解决方案,但我仍然不满意.
问题:
我希望能够像AppStore中的WidgetLocker应用程序一样覆盖HOME按钮功能.WidgetLocker不是一个家庭发射器,它仍然可以比任何人更好地覆盖HOME.
放弃
解决方案
有没有其他方法可以做到这一点?
提前致谢.
是否可以在我的应用程序中在锁定屏幕上显示信息?例如,倒数计时器?我知道 Apple 的内置应用程序,例如时钟,可以做到这一点。但它是否可以使用公共 API?
不,我不是在谈论推送或本地通知。我想为我的目的显示和实际倒数计时器,以便用户可以关闭应用程序并通过扫一眼锁定屏幕来获取计时器的更新。
所以,我通过网络搜索,并没有看到任何人遇到我遇到的这个问题。
我正在构建一个需要推送通知的应用程序。推送通知显示在状态栏和锁定屏幕上,但仅在应用程序处于活动状态时发出声音。我不知道我错过了什么。
这是我的代码:
public class PushListenerService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d("FROM", from);
Bundle pushNotification = (Bundle) data.get("notification");
String title = pushNotification.get("title").toString();
String body = pushNotification.get("body").toString();
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager notificationManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder notification = new Notification.Builder(this);
notification.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.portrait_front)
.setSound(alarmSound);
notificationManager.notify(0, notification.build());
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
编辑:添加清单以供进一步检查:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sth.idapp.android.privateapp">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name=".start.StartActivity"
android:theme="@style/AppTheme.HideActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> …Run Code Online (Sandbox Code Playgroud) 我正在开发音乐应用程序,但对于锁定屏幕控制,我无法分配持续时间和已用时间
这是我的代码
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.previousTrackCommand.isEnabled = true;
commandCenter.previousTrackCommand.addTarget(self, action:#selector(home_ViewController.btn_rewind(_:)))
commandCenter.nextTrackCommand.isEnabled = true
commandCenter.nextTrackCommand.addTarget(self, action:#selector(home_ViewController.btn_fast(_:)))
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget(self, action:#selector(home_ViewController.play_player))
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget(self, action:#selector(home_ViewController.pause_player))
commandCenter.togglePlayPauseCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.addTarget(self, action:#selector(home_ViewController.togglePlay_Pause))
commandCenter.skipBackwardCommand.isEnabled = false
commandCenter.skipForwardCommand.isEnabled = false
if #available(iOS 9.1, *) {
commandCenter.changePlaybackPositionCommand.isEnabled = true
} else {
// Fallback on earlier versions
return
}
Run Code Online (Sandbox Code Playgroud)
和媒体信息
func setLockInfo()
{
let url = URL(string: song_UrlString)
let data = try? Data(contentsOf: url!)
let art = MPMediaItemArtwork.init(image: UIImage(data: data!)!)
let songInfo :[String : …Run Code Online (Sandbox Code Playgroud) 我在锁定屏幕中显示了一个自定义通知。单击通知后,我正在使用广播待处理意图向我的应用程序发送消息。稍后在广播接收器中启动一个活动。
问题是,一旦我点击通知,它就会从锁屏中消失,并且活动在锁屏后面启动。它不会要求用户解锁屏幕。
我的要求是要求用户在通知的点击事件发送广播后立即解锁屏幕。我怎么做?
我可以找到这个看起来像我的问题的问题。但不幸的是,没有答案。
这是一些解释我所做的通知创建的代码。
/**
* Method to render Notification
*/
private void showNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
/* set mandatory stuff on builder */
Notification notification = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notification.bigContentView = createCustomView(context);
}
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(getNotificationId(), notification);
}
/**
* Method to return notification click's PendingIntent
*/
private PendingIntent getNotificationClickIntent() {
Intent bcIntent = new Intent(OPEN_APP);
bcIntent.putExtra(EXTRA_DEEP_LINK_URL, getDeepLinkUrl());
return PendingIntent.getBroadcast(
context, getReqCode(), bcIntent, PendingIntent.FLAG_ONE_SHOT);
}
/**
* …Run Code Online (Sandbox Code Playgroud) 我能够在Oreo之前成功地在API上的锁定屏幕上添加一个对话框.似乎谷歌不再允许TYPE_SYSTEM_ERROR这个API上的标志了.
有没有办法在Android O上的锁定屏幕上显示对话框?
适用于<Android O的代码
int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DIM_BEHIND;
int type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
0,
0,
type,
flags,
PixelFormat.RGBA_8888);
Run Code Online (Sandbox Code Playgroud)