Der Vordergrunddienst im InstantApp-Feature-Modul kann nicht verwendet werden. Unterlauf-Sicherheitsausnahme erreichen.Android InstantApp: Vordergrunddienst
java.lang.RuntimeException: Kann Aktivität ComponentInfo {starten. .XYZActivity}: java.lang.SecurityException: Methode Klasse android.app.ActivityManagerProxy.getServices nicht zur Verfügung Instant Apps
Android Dokument sagt,
Eingeschränkte Funktionen: Run auf das Gerät ohne Benutzer bewusst. Vordergrunddienste sind verfügbar. Instant-Apps können nur durch Aktivitäten gestartet werden, die App-Links unterstützen. Daher können Dienste, Content-Provider oder Broadcast-Empfänger Ihre App nicht starten.
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();
}
}
Schnelle Frage: Können Sie bestätigen, dass die von PendingIntent.getActivity zurückgegebene ausstehende Absicht nicht null ist? Nicht, dass es verwandt ist, es ist direkt mit dem Problem verbunden, das Sie haben, aber ich sehe, dass keine ausstehenden Absichten erstellt werden. –