我有代码在幕后运行服务。当我们将文本复制到手机时,它被设置为运行。此代码在下面的 Android 8 上运行良好但问题是当我在 Android 8 及更高版本上运行该应用程序时
在我的搜索中,我意识到我必须使用 FOREGROUND_SERVICEs 并提供对项目的特定访问权限。
你现在建议什么解决方案?
public class AutoDownloadService extends Service {
private ClipboardManager mClipboardManager;
public static final String CHANNEL_ID = "ForegroundServiceChannel";
@Override
public void onCreate() {
super.onCreate();
mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
mClipboardManager.addPrimaryClipChangedListener(mOnPrimaryClipChangedListener);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String input = intent.getStringExtra("inputExtra");
createNotificationChannel();
Intent notificationIntent = new Intent(this, SettingsActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Foreground Service")
.setContentText(input)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pendingIntent)
.build(); …
Run Code Online (Sandbox Code Playgroud) 这些是我启用 allowBackup 后的代码
<application
android:name=".utils.MyApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
当我得到输出时,我遇到了以下问题
Error:Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:20:9-36
is also present at [me.itangqi.waveloadingview:library:0.3.5] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:18:5-55:19 to override.
Run Code Online (Sandbox Code Playgroud)