Impossible d'utiliser le service de premier plan dans le module de fonction InstantApp. Obtention d'une exception de sécurité d'exécution en dessous.Android InstantApp: service de premier plan
java.lang.RuntimeException: Impossible de démarrer l'activité ComposantInfo {. .XYZActivity}: java.lang.SecurityException: Méthode android.app.ActivityManagerProxy.getServices de classe ne sont pas disponibles pour applications instantanées
Document Android dit,
fonctionnalités restreintes: Run sur l'appareil sans que les utilisateurs en soient conscients. Des services d'avant-plan sont disponibles. Les applications instantanées ne peuvent être démarrées que par le biais d'activités prenant en charge les liens d'application. Par conséquent, les fournisseurs de contenu ou les récepteurs de diffusion ne pourront pas démarrer votre application .
code:
// Starting service
getAppContext().startService(new Intent(getAppContext(), FirebaseAuthService.class));
// Foreground service class
public class FirebaseAuthService extends Service {
private static final String TAG = "FirebaseAuthService";
private boolean isRunning = false;
private String mUserId;
private FirebaseAuth mAuth;
@Override
public void onCreate() {
Log.d(TAG, "Service onCreate");
startForeground();
isRunning = true;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Service onStartCommand");
new Thread(new Runnable() {
@Override
public void run() {
myTask();
}
}).start();
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
Log.i(TAG, "Service onBind");
return null;
}
@Override
public void onDestroy() {
isRunning = false;
Log.i(TAG, "Service onDestroy");
}
private void startForeground() {
Intent notificationIntent = new Intent(this, HomeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.noti_logo)
.setContentTitle("Title")
.setContentText("Preparing...")
.setContentIntent(pendingIntent).build();
startForeground(1337, notification);
}
private void myTask() {
// At end
// Stop service once it finishes its task
stopSelf();
}
}
Question rapide: pourriez-vous confirmer que l'intention en attente renvoyée par PendingIntent.getActivity n'est pas nulle? Ce n'est pas lié, c'est directement lié à la question que vous avez, mais je vois qu'aucune intention en attente n'est créée. –