我正在尝试使用以下代码让我的应用关闭音乐播放器:
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
ActivityManager activityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
String music = "com.sec.android.app.music";
activityManager.killBackgroundProcesses(music);
}
}
但它只是调低音量,而不是杀死应用程序。我已经向清单添加了适当的权限,并且我的目标是高于 API 8 谢谢。