我按照上面关于如何创建 Android 快速设置图块的所有内容操作,但似乎没有任何效果。我的图块似乎没有出现在自定义图块上。
我的源代码有什么问题?我已经在三星、Pixels、Vivo 等不同的智能手机上测试过此应用,但在添加自定义图块部分似乎看不到我的快速设置图块。
这是我的服务课程
package quick_settings_tile;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.util.Log;
import android.widget.Toast;
public class QuickTileService extends TileService {
// Called when the user adds your tile.
@Override
public void onTileAdded() {
super.onTileAdded();
try {
// Existing onClick code
Tile tile = getQsTile();
tile.setState(Tile.STATE_ACTIVE);
tile.updateTile();
Log.d("QuickTileService", "Tile added");
} catch (Exception e) {
Log.e("QuickTileService", "Crash: " + e.getMessage());
}
}
// Called when your app can update your tile.
@Override
public void onStartListening() {
super.onStartListening();
try {
Tile tile = getQsTile();
tile.setState(Tile.STATE_ACTIVE);
tile.updateTile();
Log.d("QuickTileService", "Tile listening");
} catch (Exception e) {
Log.e("QuickTileService", "Crash: " + e.getMessage());
}
}
// Called when the user taps on your tile in an active or inactive state.
@Override
public void onClick() {
super.onClick();
try {
// Existing onClick code
Tile tile = getQsTile();
Log.d("QuickTileService", "Clicked Label: " + tile.getLabel());
Toast.makeText(this, "Hello, we are almost there!!!!!!!!!!!!", Toast.LENGTH_SHORT).show();
getQsTile().updateTile();
} catch (Exception e) {
Log.e("QuickTileService", "Crash: " + e.getMessage());
}
}
// Called when the user removes your tile.
@Override
public void onTileRemoved() {
super.onTileRemoved();
try {
// Existing onClick code
Log.d("QuickTileService", "Service removed");
} catch (Exception e) {
Log.e("QuickTileService", "Crash: " + e.getMessage());
}
}
@Override
public void onCreate() {
super.onCreate();
try {
// Existing onClick code
Log.d("QuickTileService", "Service created");
} catch (Exception e) {
Log.e("QuickTileService", "Crash: " + e.getMessage());
}
}
}
我的 Android 清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Wire"
tools:targetApi="31">
<activity
android:name="receipts.ReceiptActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="quick_settings_tile.QuickTileService"
android:label="Pay bill"
android:icon="@drawable/white_qr_code_scanner"
android:exported="true"
android:permission="android.permission.BIND_QUICK_SETTINGS">
<meta-data android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
</application>
</manifest>
我尝试了在线教程中提到的所有方法。在我这边,当我测试应用程序时,我没有看到结果。就像看到快速设置图块一样。
更改权限名称
到:
定义在TileService中