簡體   English   中英

的清單名稱屬性 <service> 標簽

[英]Manifest name attribute of <service> tag

根據清單元素中的文檔

<service android:name=".PrinterService" 

應該是Service子類的指定名稱。 我的子類名為PrinterService,其定義如下

package arrowsys.vrp.print;

#import
public class PrinterService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    public class PrinterSession extends PrinterDiscoverySession {
    }
}

當我輸入屬性名稱.PrinterService

無法解析符號

與價值.service.PrinterService我得到

預期的AidleType軟件包為“。”。

編輯:為了更簡單,我已經刪除了arrowsys.vrp.printer / service文件夾,所以我的PrinterService.java直接在arrowsys.vrp.printer中。

現在,程序包定義為package arrowsys.vrp.print

完整的AndroidManifest.xaml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="arrowsys.vrp.print">
    <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="arrowsys.vrp.print.PrinterService"
            android:description="@string/app_name"
            android:permission="android.permission.BIND_PRINT_SERVICE" >
            <intent-filter>
                <action android:name="android.vrp.print.PrinterService" />
            </intent-filter>
        </service>
    </application>
</manifest>

根據App Manifest文檔,您必須包括完整的程序包路徑,否則您的服務應為該應用程序包的子級

如果定義一個子類,就幾乎像組件類(Activity,Service,BroadcastReceiver和ContentProvider)一樣定義子類,則該子類是通過name屬性聲明的。 名稱必須包含完整的包裝名稱。 例如,一個服務子類可能聲明如下:

<manifest . . . >
<application . . . >
    <service android:name="com.example.project.SecretService" . . . >
        . . .
    </service>
    . . .
</application>

但是,如果字符串的第一個字符是句點,則將應用程序的程序包名稱(由元素的package屬性指定)附加到字符串中。

<manifest package="com.example.project" . . . >
<application . . . >
    <service android:name=".SecretService" . . . >
        . . .
    </service>
    . . .
</application>

我的猜測是您的清單軟件包不是arrowsys.vrp.print ,因此您必須使用<service android:name="arrowsys.vrp.print.service.PrinterService">

嘗試

<service android:name="arrowsys.vrp.print.service.PrinterService">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM