質問編集履歴
2
アラーム鳴動用のソース(スクリーンロック解除部分)及びアプリのManifestを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -120,11 +120,6 @@
|
|
120
120
|
.setContentText(context.getString(R.string.setTimeCame))
|
121
121
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
122
122
|
.setCategory(NotificationCompat.CATEGORY_ALARM)
|
123
|
-
// Use a full-screen intent only for the highest-priority alerts where you
|
124
|
-
// have an associated activity that you would like to launch after the user
|
125
|
-
// interacts with the notification. Also, if your app targets Android 10
|
126
|
-
// or higher, you need to request the USE_FULL_SCREEN_INTENT permission in
|
127
|
-
// order for the platform to invoke this notification.
|
128
123
|
.setFullScreenIntent(fullScreenPendingIntent, true);
|
129
124
|
|
130
125
|
Notification incomingCallNotification = notificationBuilder.build();
|
@@ -159,13 +154,9 @@
|
|
159
154
|
// 一意のチャンネルID
|
160
155
|
// ここはどこかで定数にしておくのが良さそう
|
161
156
|
CHANNEL_ID,
|
162
|
-
|
163
157
|
// 設定に表示されるチャンネル名
|
164
|
-
// ここは実際にはリソースを指定するのが良さそう
|
165
158
|
CHANNEL_NAME,
|
166
|
-
|
167
159
|
// チャンネルの重要度
|
168
|
-
// 重要度によって表示箇所が異なる
|
169
160
|
NotificationManager.IMPORTANCE_DEFAULT
|
170
161
|
);
|
171
162
|
// 通知時にライトを有効にする
|
@@ -196,4 +187,88 @@
|
|
196
187
|
keylock.disableKeyguard();
|
197
188
|
}
|
198
189
|
}
|
190
|
+
```
|
191
|
+
####アラームのアクティビティ(画面立ち上げ部分とアラーム部分 他は長いため省略)
|
192
|
+
Alarm_vib.java
|
193
|
+
```java
|
194
|
+
@Override
|
195
|
+
protected void onCreate(Bundle savedInstanceState) {
|
196
|
+
super.onCreate(savedInstanceState);
|
197
|
+
setContentView(R.layout.vib_layout);
|
198
|
+
//スリープの解除
|
199
|
+
wakeFromSleep();
|
200
|
+
/*
|
201
|
+
省略
|
202
|
+
*/
|
203
|
+
//アラームの再セット
|
204
|
+
Alarm_set();
|
205
|
+
//バイブの起動
|
206
|
+
VibeOn();
|
207
|
+
}
|
208
|
+
|
209
|
+
//スリープ解除関数
|
210
|
+
private void wakeFromSleep() {
|
211
|
+
// Lock解除画面より手前に表示させる
|
212
|
+
final Window win = getWindow();
|
213
|
+
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
214
|
+
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
215
|
+
|
216
|
+
wakelock = ((PowerManager) getSystemService(android.content.Context.POWER_SERVICE))
|
217
|
+
.newWakeLock(PowerManager.FULL_WAKE_LOCK
|
218
|
+
| PowerManager.ACQUIRE_CAUSES_WAKEUP
|
219
|
+
| PowerManager.ON_AFTER_RELEASE, "vib:disableLock");
|
220
|
+
wakelock.acquire();
|
221
|
+
|
222
|
+
wakelock.release();
|
223
|
+
//ロック解除
|
224
|
+
KeyguardManager keyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
|
225
|
+
keylock = keyguard.newKeyguardLock("disableLock");
|
226
|
+
keylock.disableKeyguard();
|
227
|
+
}
|
228
|
+
```
|
229
|
+
####アプリのManifest(長いので一部省略)
|
230
|
+
```xml
|
231
|
+
<?xml version="1.0" encoding="utf-8"?>
|
232
|
+
<manifest>
|
233
|
+
|
234
|
+
<!--パーミッション-->
|
235
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
236
|
+
<uses-permission android:name="android.permission.VIBRATE" />
|
237
|
+
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
|
238
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
239
|
+
<!--アプリ-->
|
240
|
+
<application
|
241
|
+
android:name=".MyApplication"
|
242
|
+
android:allowBackup="true"
|
243
|
+
android:icon="@mipmap/ic_launcher"
|
244
|
+
android:label="@string/app_name"
|
245
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
246
|
+
android:supportsRtl="true"
|
247
|
+
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
<!--一部省略-->
|
252
|
+
<!--アラーム鳴動用-->
|
253
|
+
<activity android:name=".Alarm_vib">
|
254
|
+
<intent-filter>
|
255
|
+
<action android:name="android.intent.action.MAIN" />
|
256
|
+
<category android:name="android.intent.category.DEFAULT" />
|
257
|
+
</intent-filter>
|
258
|
+
</activity>
|
259
|
+
<!--時間になった時の受け取り-->
|
260
|
+
<receiver
|
261
|
+
android:name=".AlarmBroadcastReceiver"
|
262
|
+
android:process=":remote">
|
263
|
+
<intent-filter>
|
264
|
+
<category android:name="android.intent.category.DEFAULT" />
|
265
|
+
</intent-filter>
|
266
|
+
</receiver>
|
267
|
+
<!--サービス起動用-->
|
268
|
+
<service android:name=".StartVibeService" />
|
269
|
+
|
270
|
+
<!--一部省略-->
|
271
|
+
|
272
|
+
</application>
|
273
|
+
</manifest>
|
199
274
|
```
|
1
参考欄のアプリを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,7 +22,8 @@
|
|
22
22
|
|
23
23
|
##参考
|
24
24
|
ロックが設定されているandroid10の機種でもロック画面の上にActivityを表示できるアラーム系アプリ
|
25
|
-
[アラームアプリ](https://play.google.com/store/apps/details?id=jp.tanyu.SmartAlarmFree&hl=en_US)
|
25
|
+
[アラームアプリ1](https://play.google.com/store/apps/details?id=jp.tanyu.SmartAlarmFree&hl=en_US)
|
26
|
+
[アラームアプリ2](https://play.google.com/store/apps/details?id=hdesign.theclock)
|
26
27
|
|
27
28
|
#ソースコード
|
28
29
|
####サービス起動用ブロードキャスト
|