當服務代碼位於與主應用程序的MainActivity不同的包中的另一個包中時,我似乎無法啓動我的android服務。從不同的包中啓動Android服務
我已經嘗試了很多很多方法,即使是AIDL方法,我也無法得到它的工作。
MainActivity代碼
ServiceIntent.setComponent(new ComponentName("com.service.luna","com.service.luna.VService"));
bindService(ServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
MainActivty艙單
<?xml version="1.0" encoding="utf-8"?>
<!-- <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> This is set from Gradle -->
<!-- Needed for camera passthrough -->
<!--<uses-permission android:name="android.permission.CAMERA" />-->
<!-- Needed to write thumbs -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Needed to for volume -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- Needed for Google Play Services GPS -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.usb.host" />
<!-- Needed for uploading crash reports -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"
android:hardwareAccelerated="true" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
<!-- singleTask launchMode because we never want multiple copies of the app running, -->
<!-- but we might want to internally spawn other activities -->
<!-- Theme.DeviceDefault.NoActionBar.Fullscreen gives solid black instead of a (bad stereoscopic) gradient on app transition -->
<activity android:name="com.main.luna.MainActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="screenSize|orientation|keyboardHidden|keyboard"
>
<!-- this filter lets the apk show up as a launchable icon -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.service.luna.VService" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.service.luna.VService" android:process=":VServiceRemote" android:exported="true" android:enabled="true">
<intent-filter>
<action android:name="com.service.luna.VService"/>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<receiver android:name="com.main.luna.ConnectivityChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
</application>
服務代碼
public class VService extends Service implements Serializable{
....
服務清單
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.service.luna">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
當我的代碼運行。最後,我收到
bindService callerProcessName:com.main.luna, calleePkgName: com.service.luna, action: null
Unable to start service Intent { pkg=com.service.luna cmp=com.service.luna/.VService } U=0: not found
主包的名稱爲com .main.luna,該服務位於com.service.luna
如果以前有人解決過這個問題,請告訴我。
我解決了這個遲緩.....這是谷歌的Android的研究與開發。我不得不在主活動包中啓動這個意圖,如 ServiceIntent.setComponent(new ComponentName(「com.main.luna」,「com.service.luna.VService」)); – Perjia