對於我的Android應用程序,我添加了一個AppTile。大多數時候,這個AppTile 是不可點擊的。它的圖標是灰色的,如禁用或不可圖標(https://developer.android.com/reference/android/service/quicksettings/Tile.html#STATE_UNAVAILABLE)Android AppTileService onClick不會被調用
在我的日誌此行從未達到
Logger.d(getClass(), "onClick()");
但我測試過該方法onStartListening()或onStopListening( )每當AppTile變爲可見或隱藏時調用。
AppTileService.java
package my.package
import android.os.Build;
import android.service.quicksettings.TileService;
import android.support.annotation.RequiresApi;
import my.package.utils.Logger;
@RequiresApi(api = Build.VERSION_CODES.N)
public class AppTileService extends TileService {
@Override
public void onClick() {
Logger.d(getClass(), "onClick()");
if (isSecure()) {
Logger.d(getClass(), "isSecure = true");
NotificationHandler.showDirectReplyNotification(this);
}
}
}
AndroidManifest.xml中
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.package">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service
android:name=".AppTileService"
android:icon="@drawable/tile_icon"
android:label="@string/app_name"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
</application>
</manifest>
有人能告訴我這可能是什麼,或者是否已經忘記了什麼來實現?
謝謝,我已經加入你的建議,並必須刪除平鋪一次並重新添加到快速設置。現在它像一個魅力 – Larcado