gpt4 book ai didi

android - 更改 Android 的默认 MediaPlayer User-Agent 字符串

转载 作者:行者123 更新时间:2023-11-29 02:11:13 26 4
gpt4 key购买 nike

是否可以更改 Android 的默认 MediaPlayer User-Agent 字符串?如果是,怎么办?

最佳答案

    String referer="Referer: http://www.google.com/\r\n",
useragent="USER-AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36\r\n";
Map<String,String>mhead;
VideoView vp;
void prepareHeader(){
mhead=new HashMap<String,String>();
if(android.os.Build.VERSION.SDK_INT >20){
//if 5.X or higher, Fix User-Agent be force set by system
mhead.put(referer.split(": ")[0],referer.split(": ")[1]);
mhead.put(useragent.split(": ")[0],useragent.split(": ")[1]);//"User-Agent" => "USER-AGENT"
}else{
//if 4.X or lower, Fix Referer cannot be set
mhead.put(useragent.split(": ")[0],useragent.split(": ")[1]+referer);//"User-Agent: ... \r\nReferer: ..."
}
setVideoURI(Uri.parse(path),mhead);
}
void setVideoURI(Uri uri,Map<String,String>mHeaders){
try{
Class vpclass=Class.forName("android.widget.VideoView");
Method[]ms=vpclass.getMethods();
Method mTarget=null;
for(Method m:ms){
if(m.getName().equals("setVideoURI"))
if(m.getParameterTypes().length==2) mTarget=m;
}
if(mTarget==null){
//AlertDialog(this,"Set Headers Fail","Sorry... your device is not support this way.","ok");
}else{
mTarget.invoke(vp,new Object[]{uri,mHeaders});
}
}catch(Exception e){
//AlertDialog(this,"Set Headers Fail",Arrays.toString(e.getStackTrace()),"ok");
}
}

我测试过,它适用于:

宇龙酷派8722V安卓5.1

Nox AVD Android 4.4

希望在您的设备上工作!

关于android - 更改 Android 的默认 MediaPlayer User-Agent 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7267502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com