2

InstantAppフィーチャーモジュール内でフォアグラウンドサービスを使用できません。ランタイムセキュリティ例外を下回るAndroid InstantApp:フォアグランドサービス

java.lang.RuntimeException:アクティビティを開始できません。 ComponentInfo { .XYZActivity}:java.lang.SecurityException:メソッド インスタントのアプリへ クラスandroid.app.ActivityManagerProxy.getServices利用できません

Androidのドキュメントは言う、

制限機能:ランでユーザーがいないデバイスは認識しています。 フォアグランドサービスが利用可能です。インスタントアプリは、アプリリンクをサポートするアクティビティでのみ開始できるため、サービス、 コンテンツプロバイダまたはブロードキャスト受信者は アプリを開始できません。

コード:

// 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(); 
    } 
} 
+0

簡単な質問:PendingIntent.getActivityから返された保留中のインテントがnullではないことを確認できましたか?それはあなたが持っている問題に直接関連しているということではありませんが、保留中の意図は作成されていません。 –

答えて

2

あなたのコードが正しいですが、フォアグラウンドサービスが原因インスタントアプリの監督で知られている問題に、現時点では動作していません。

+1

チケットIDはありますか? – mol

+0

残念ながら公開されていません。 – ibrahimkarahan

+0

問題が発生しました:https://github.com/googlesamples/android-instant-apps/issues/15 –

関連する問題