Как создать рамку, которая открывается автоматически?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как создать рамку, которая открывается автоматически?

Сообщение Anonymous »

Я разрабатываю приложение для Android с Expo Framework (нет версии iOS).
Я хочу интегрировать функцию автоматического открытия при разблокировке телефона, поэтому я изменил свой код Kotlin, присутствующий в папке ./android/, а также файл Androidmanifest.xml. Этот кадр также должен закрыться при нажатии. < /P>
У меня есть две основные проблемы:
- my action_boot_completed событие никогда не запускает
- я понятия не имею, как открыть рамку Expo (т.е. через файл myframe.tsx) < /p>
P>STRONG> и поход. /mainservice.kt

Код: Выделить всё

package fr.devsoleo.activmotiv

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.IBinder
import androidx.annotation.RequiresApi
import fr.devsoleo.activmotiv.popup.PresenceReceiver

class MainService : Service() {
private val receiver = PresenceReceiver()

override fun onCreate() {
super.onCreate()
val filter = IntentFilter(Intent.ACTION_USER_PRESENT)
applicationContext.registerReceiver(receiver, filter)
}

override fun onDestroy() {
applicationContext.unregisterReceiver(receiver)
}

override fun onBind(intent: Intent?): IBinder? {
return null
}

@RequiresApi(Build.VERSION_CODES.O)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
startNotification()
return START_STICKY
}

@RequiresApi(Build.VERSION_CODES.O)
private fun startNotification() {
val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_DEFAULT).apply {
description = "ActivMotiv Notification Channel"
}

val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)

val notification: Notification = Notification.Builder(this, CHANNEL_ID)
.setContentTitle("Notification titre")
.setContentText("Notification contenu")
.build()

startForeground(2, notification)
}

companion object {
const val CHANNEL_ID = "ActivMotivNotif"
const val CHANNEL_NAME = "ActivMotiv"
}
}
/bootreceiver.kt

Код: Выделить всё

class BootReceiver : BroadcastReceiver() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
val serviceIntent = Intent(context, MainService::class.java)
context.startForegroundService(serviceIntent)
}
}
}
/popup/preserceceiver.kt

Код: Выделить всё

package fr.devsoleo.activmotiv.popup

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class PresenceReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_USER_PRESENT) {
val startIntent = Intent(context, ImagesActivity::class.java)
startIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
context.startActivity(startIntent)
}
}
}
/popup/imageactivity.kt

Код: Выделить всё

package fr.devsoleo.activmotiv.popup

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity

class ImagesActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onRestart() {
super.onRestart()
}

override fun onResume() {
super.onResume()
}

override fun onStop() {
super.onStop()
}
}
Мне удалось получить автоматическое открытие для работы (на пустой деятельности), но я не могу вернуться к этой стадии. 53.
На данный момент ничего не работает.
Заранее!

Подробнее здесь: https://stackoverflow.com/questions/797 ... omatically
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»