如何更改targetSdkVersion

如何更改targetSdkVersion,targetsdkversion,Targetsdkversion,我的目标targetSdkVersion有问题。我想从27移到29,但当更改为sdk 29时,应用程序会运行,但不会显示视频。但当它是sdk 27或更低版本时,它会显示视频。 有人能帮我修一下吗 /** *一个简单的{@link Fragment}子类。 */ 公共类ChannelFragment扩展了片段{ 私有静态字符串GOOGLE_YOUTUBE_API_KEY=“aizasybjqypqrtzm5wuhmuxmp7rvp3lbmgtuz8”//这里您应该使用API密钥进行测试,您也可以

我的目标targetSdkVersion有问题。我想从27移到29,但当更改为sdk 29时,应用程序会运行,但不会显示视频。但当它是sdk 27或更低版本时,它会显示视频。 有人能帮我修一下吗

/**
*一个简单的{@link Fragment}子类。 */ 公共类ChannelFragment扩展了片段{ 私有静态字符串GOOGLE_YOUTUBE_API_KEY=“aizasybjqypqrtzm5wuhmuxmp7rvp3lbmgtuz8”//这里您应该使用API密钥进行测试,您也可以使用此API 私有静态字符串CHANNEL\u ID=“UCB\u ZwuWCAuB7y0B93qvnkWw”//这里您应该使用您的通道ID进行测试,您也可以使用此api 私有静态字符串CHANNLE_GET_URL=“+CHANNEL_ID+”&maxResults=50&key=“+GOOGLE_YOUTUBE_API_key+”

private RecyclerView mList_videos=null;
专用VideoPostAdapter适配器=空;
private ArrayList mListData=new ArrayList();
公共频道片段(){
//必需的空公共构造函数
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
视图=充气机。充气(R.layout.fragment_通道,容器,错误);
mList_videos=(RecyclerView)view.findviewbyd(R.id.mList_videos);
initList(mListData);
新请求youtubeapi().execute();
返回视图;
}
私有void initList(ArrayList mListData){
mList_videos.setLayoutManager(新的LinearLayoutManager(getActivity());
适配器=新的VideoPostAdapter(getActivity(),mListData,new OnItemClickListener()){
@凌驾
公共物品(YoutubeDataModel项目){
YoutubeDataModel YoutubeDataModel=项目;
Intent Intent=new Intent(getActivity(),DetailsActivity.class);
intent.putExtra(YoutubeDataModel.class.toString(),YoutubeDataModel);
星触觉(意向);
}
});
mList_videos.setAdapter(适配器);
}
//创建asynctask以从youtube获取所有数据
私有类RequestYoutubeAPI扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
}
@凌驾
受保护字符串doInBackground(无效…参数){
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpGet HttpGet=新的HttpGet(CHANNLE\u GET\u URL);
Log.e(“URL”,CHANNLE\u GET\u URL);
试一试{
HttpResponse response=httpClient.execute(httpGet);
HttpEntity HttpEntity=response.getEntity();
字符串json=EntityUtils.toString(httpEntity);
返回json;
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串响应){
super.onPostExecute(响应);
if(响应!=null){
试一试{
JSONObject JSONObject=新JSONObject(响应);
Log.e(“response”,jsonObject.toString());
mListData=parseVideoListFromResponse(jsonObject);
initList(mListData);
}捕获(JSONException e){
e、 printStackTrace();
}
}
}
}
公共ArrayList parseVideoListFromResponse(JSONObject JSONObject){
ArrayList mList=新的ArrayList();
如果(jsonObject.has(“项”)){
试一试{
JSONArray JSONArray=jsonObject.getJSONArray(“项”);
for(int i=0;i

}

请在此处发布您迄今为止尝试的代码。谢谢Kiran Maniya。我为我的公司设计了一个实时流媒体应用程序,但如果targetsdkversion高于27,则频道视频不会显示,但当targetsdkversion高于27时会显示。我发布代码供您查看。提前谢谢谢谢您。提前谢谢。请不要发布问题现在。似乎我现在不知道如何使用这个地方。你能给我你的电子邮件或帮我发送整个代码给你,让你帮我检查吗?谢谢。我想我可能会发布代码,但在网站上有格式问题。我可以将整个文件发送给任何能帮我修复它的人。谢谢
private RecyclerView mList_videos = null;
private VideoPostAdapter adapter = null;
private ArrayList<YoutubeDataModel> mListData = new ArrayList<>();

public ChannelFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_channel, container, false);
    mList_videos = (RecyclerView) view.findViewById(R.id.mList_videos);
    initList(mListData);
    new RequestYoutubeAPI().execute();
    return view;
}

private void initList(ArrayList<YoutubeDataModel> mListData) {
    mList_videos.setLayoutManager(new LinearLayoutManager(getActivity()));
    adapter = new VideoPostAdapter(getActivity(), mListData, new OnItemClickListener() {
        @Override
        public void onItemClick(YoutubeDataModel item) {
            YoutubeDataModel youtubeDataModel = item;
            Intent intent = new Intent(getActivity(), DetailsActivity.class);
            intent.putExtra(YoutubeDataModel.class.toString(), youtubeDataModel);
            startActivity(intent);
        }
    });
    mList_videos.setAdapter(adapter);

}


//create an asynctask to get all the data from youtube
private class RequestYoutubeAPI extends AsyncTask<Void, String, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();


    }


    @Override
    protected String doInBackground(Void... params) {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(CHANNLE_GET_URL);
        Log.e("URL", CHANNLE_GET_URL);
        try {
            HttpResponse response = httpClient.execute(httpGet);
            HttpEntity httpEntity = response.getEntity();
            String json = EntityUtils.toString(httpEntity);
            return json;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }


    @Override
    protected void onPostExecute(String response) {
        super.onPostExecute(response);
        if (response != null) {
            try {
                JSONObject jsonObject = new JSONObject(response);
                Log.e("response", jsonObject.toString());
                mListData = parseVideoListFromResponse(jsonObject);
                initList(mListData);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}

public ArrayList<YoutubeDataModel> parseVideoListFromResponse(JSONObject jsonObject) {
    ArrayList<YoutubeDataModel> mList = new ArrayList<>();

    if (jsonObject.has("items")) {
        try {
            JSONArray jsonArray = jsonObject.getJSONArray("items");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json = jsonArray.getJSONObject(i);
                if (json.has("id")) {
                    JSONObject jsonID = json.getJSONObject("id");
                    String video_id = "";
                    if (jsonID.has("videoId")) {
                        video_id = jsonID.getString("videoId");
                    }
                    if (jsonID.has("kind")) {
                        if (jsonID.getString("kind").equals("youtube#video")) {
                            YoutubeDataModel youtubeObject = new YoutubeDataModel();
                            JSONObject jsonSnippet = json.getJSONObject("snippet");
                            String title = jsonSnippet.getString("title");
                            String description = jsonSnippet.getString("description");
                            String publishedAt = jsonSnippet.getString("publishedAt");
                            String thumbnail = jsonSnippet.getJSONObject("thumbnails").getJSONObject("high").getString("url");

                            youtubeObject.setTitle(title);
                            youtubeObject.setDescription(description);
                            youtubeObject.setPublishedAt(publishedAt);
                            youtubeObject.setThumbnail(thumbnail);
                            youtubeObject.setVideo_id(video_id);
                            mList.add(youtubeObject);

                        }
                    }
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    return mList;

}