私はこの問題を解決するためにあらゆるところを調査しましたが、私はそれが自分のマニフェストファイルと関係していると確信しています。ログに、 contextService = IContextInterface.Stub.asInterface(service)
に以下のコードを接続するためのコードの印刷をしようとすると、サービスオブジェクトがまだnullであることを示すAIDLでサービスにアプリケーションをバインドする際の問題
contextServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
contextService = IContextInterface.Stub.asInterface(service);
Toast.makeText(getApplicationContext(),
"Context Service Connected", Toast.LENGTH_SHORT)
.show();
Log.d("IApp", "Binding is done - Context Service connected");
}
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
contextService = null;
Toast.makeText(getApplicationContext(), "Service Disconnected",
Toast.LENGTH_SHORT).show();
Log.d("IRemote", "Binding - Location Service disconnected");
}
};
if (contextService == null) {
Intent contextIntent = new Intent();
contextIntent.setPackage("com.example.the_f.myapplication");
contextIntent.setAction("service.contextFinder");
bindService(contextIntent, contextServiceConnection, Context.BIND_AUTO_CREATE);
mContextIsBound = true;
if(contextService==null)
Log.d("locService","NULL");
}
その場合はnull、それはしようとしますように、私も、それをもう一度確認してください手動でバインドします。しかし、ログが "locService:NULL"を出力しているので、最後のif文にはまだヒットしています。ここで
私のクライアントアプリケーションマニフェストです:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
、ここでは私のリモートサービスマニフェストです:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyMiddleware"
android:enabled="true"
android:exported="true"></service>
</application>
私はそれが間違って構築されたか、どこかに埋もれ、いくつかのファイルに問題があった考え続けているため、IVEは、このプログラムを3回再起動します。私は本当にアンドロイドプロではないので、多くのことをよく知っていません。どんな助けや指導もいただければ幸いです。ありがとうございます。
あなたはonServiceConnectedを待たなければなりません。 – natario
よろしくお願いします。私はprintステートメントをonServiceConnectedに落とし、そのステートメントを呼び出さなかった。私は何をしているのか分からない。私はかなり多くの例をオンラインで見たようにコピーしました。アンドロイドの開発サイトでさえ、彼らはこのように設定しています。だから明らかに私のアプリは決してサービスに接続していない –