Android ТВ-пусковая установка не запрашивает разрешения - PullRequest
0 голосов
/ 06 августа 2020

Я тоже разработчик Android, и я застрял между проектом android tv и могу получить помощь по любому программному обеспечению. Я добавил эти строки в файл манифеста Android

<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />

Я делаю пусковую установку для android телевизора, но когда я нажимаю кнопку «Домой», меня не просят установить пусковую установку по умолчанию. Вот мой AndroidManifest. xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oblate.tvproject4">

<!--    <uses-permission android:name="android.permission.INTERNET"></uses-permission>-->
<!--    For Tv app state specific hardware and software as false-->
<uses-feature android:name="android.software.leanback"
    android:required="false" />
<uses-feature android:name="android.hardware.touchscreen"
    android:required="false" />


<application
    android:banner="@drawable/ic_launcher_foreground"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Leanback">

    <activity
        android:name=".MainActivity"
        android:screenOrientation="landscape"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

И мой activity_main. xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <VideoView

        android:id="@+id/playVideo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"></VideoView>


</LinearLayout>

И я добавил это в свой build.gradle (приложение)

implementation 'com.android.support:leanback-v17:28.0.0'

И мой MainActivity . xml

package com.oblate.tvproject4;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.SystemClock;
import  android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.provider.MediaStore;
import android.widget.VideoView;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;


import java.io.File;
import java.net.URI;
import java.util.List;

public class MainActivity extends FragmentActivity {
// initializing variables which store path or files
VideoView videoToPlay;
String videoLocation;
File video;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    videoToPlay = (VideoView) findViewById(R.id.playVideo);

    //getting video file from Directory
   // video= Environment.getExternalStorageDirectory(Environment.DIRECTORY_M);
   // videoLocation = context.getFilesDir() + "/"+"Android"+"/"+"data"+"/"+"video.mp4";
   // video = new File(videoLocation);

    playAndExit();
}

private void playAndExit() {

    String videoPath = "android.resource://com.oblate.tvproject4/"+ R.raw.oblate;

    Uri uri = Uri.parse(videoPath);
    videoToPlay.setVideoURI(uri);
    // no media controller needed
    videoToPlay.start();

    long time; // getting time since reboot
    time = SystemClock.elapsedRealtime();

    int appRuntime=0; // time for which the app will run
    if(time <40000){
        appRuntime = 10000;
    } // if reboot time is above 40sec the will run for the blink of eye when clicked home


    final Handler handler = new Handler();
    handler.postDelayed(new  Runnable() {
        @Override
        public  void run(){
            PackageManager pm = getPackageManager();
            ComponentName name = new ComponentName(MainActivity.this, MainActivity.class);

            Intent i = new Intent("android.intent.action.MAIN");
            i.addCategory("android.intent.category.HOME");
            List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
            if (lst != null) {
                for (ResolveInfo resolveInfo : lst) {
                    try {
                        Intent home = new Intent("android.intent.action.MAIN");
                        home.addCategory("android.intent.category.HOME");
                        home.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
                        startActivity(home);
                        break;
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }

            finish();
            System.exit(0);
        }
    },5000); // appRunTime
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...