lmf159 发表于 2020-4-22 10:06:23

请教一个安卓问题:服务死活连不上了

最近在学adnroid 編程,学AIDL 那块。写了一个app,其中包含有一个测试的 service 和一个测试的 activity, 两者通过 AIDL 通信。没有什何问题,将service 作为一个单独的进程运行,通信都没有什么问题。但是单独写一个 app(只有一个测试 activity, 和上一个app中的 activity 相同) 与上个app中的 service 通讯,则死活连不上;但修改一下后面那个app, 不连前一个app的service 而是启动他的 activity,则没有问题。
有没有大虾知道是哪出了问题?

wx85105157 发表于 2020-4-22 16:00:06

安全问题?访问不能跨域?

lmf159 发表于 2020-4-23 09:26:07

service app 的 manifest 部分如下
    <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <service
            android:name=".MyService"
            android:process=":remote"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.example.t_service.MyService"/>
                <!--category android:name="android.intent.category.LAUNCHER" / !-->
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
      </service>

      <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
      </activity>
    </application>
客户app 中用显示的 intent 方法
Intent intent = new Intent();
intent.setClassName("com.example.t_service","com.example.t_service.MyService");
startService(intent); 和 bindService(intent, mConnection, Context.BIND_AUTO_CREATE); 都试了没用
但是换成
intent.setClassName("com.example.t_service","com.example.t_service.MainActivity");
startActivity(intent); 可以打开serviceapp 的 atcivity

service app 的 manifest中 service 节中
            android:process=":remote"
            <intent-filter>
                <action android:name="com.example.t_service.MyService"/>
                <!--category android:name="android.intent.category.LAUNCHER" / !-->
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
是用来测式的,有或没有都不行。但用service app中的activity 则没有问题。不管activity 与 service 是不是在同一个进程中(即android:process=":remote" 是否设置)
页: [1]
查看完整版本: 请教一个安卓问题:服务死活连不上了