加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

直播录屏中应用容易被杀掉解决方案

发布时间:2020-12-16 23:44:46 所属栏目:百科 来源:网络整理
导读:直播录制手机屏幕的时候应用容易被杀死,录制没有几分钟就挂了,再次点开应用就是重启的状态 在网上查询说是在AndroidMinfest.xml 的application标签里加上?android:persistent="true" 这个玩意,但是这个只有放在System/app目录下的应用加上才有用,其他的

直播录制手机屏幕的时候应用容易被杀死,录制没有几分钟就挂了,再次点开应用就是重启的状态

在网上查询说是在AndroidMinfest.xml 的application标签里加上?android:persistent="true" 这个玩意,但是这个只有放在System/app目录下的应用加上才有用,其他的应用加上也没用,也有可能崩溃

另外一种就是将应用里加上前台服务,让系统认为应用一直在被使用,从而不会被杀死

直播录屏会加上通知栏告知用户正在录屏

在当前的Activity里开启前端服务,代码如下:

public class LiveService extends Service{
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
}

@Override
public int onStartCommand(Intent intent,int flags,int startId) {
Intent it = new Intent(this,GameLiveStreamingActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(
this,it,0);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(me.lifre.live.R.drawable.icon_headview)
.setContentTitle(getString(string.recording_screen))
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setTicker(getString(R.string.recording_screen))
.setOngoing(true)
.setContentIntent(contentIntent);
Notification notification1 = notification.build();
startForeground(1,notification1);//设置为前台服务
  return super.onStartCommand(intent,flags,startId);
}

@Override
public void onDestroy() {
ISLog.d("直播测试","销毁服务");
super.onDestroy();
}
}
如此,系统就不会轻易杀死你的应用了,音乐播放器类似这些app都是这样的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读