Заранее спасибо за дальнейшие ответы
Мне удалось позвонить мой пакет, когда когда-либо пакет Android назывался com.google.android.tv launcher
Вот мой загрузочный приемник. Моя функция — это «setdefaultlauncher», который я вызываю в части «onReceive»:
Код: Выделить всё
package com.ansetech.hospitv.receiver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import com.ansetech.hospitv.activity.HomeActivity;
import com.ansetech.hospitv.service.DownloadService;
import com.ansetech.hospitv.service.NotificationService;
import com.ansetech.hospitv.service.YourBootService;
import com.ansetech.hospitvlib.util.DUtils;
/**
* Starts download service on bootup
*/
public class BootReceiver extends BroadcastReceiver {
private static final String LOG_CAT = "BootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// Set your app as the default launcher
//if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// Your code to handle boot completion goes here
// For example, you can start a service or launch an activity
setDefaultLauncher(context);
//}
// Démarrage des services.
try {
DUtils.caveman("BootReceive startForegroundService NotificationService....");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, NotificationService.class));
} else {
context.startService(new Intent(context, NotificationService.class));
}
} catch (Exception e) {
Log.e("BootReceiver", "Starting service FAILED -> NotificationService", e);
}
try {
DUtils.caveman("BootReceive startForegroundService DownloadService....");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, DownloadService.class));
} else {
context.startService(new Intent(context, DownloadService.class));
}
} catch (Exception e) {
Log.e("BootReceiver", "Starting service FAILED -> DownloadService", e);
}
// Start YourBootService
try {
DUtils.caveman("BootReceive startForegroundService YourBootService....");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, YourBootService.class));
} else {
context.startService(new Intent(context, YourBootService.class));
}
} catch (Exception e) {
Log.e("BootReceiver", "Starting service FAILED -> YourBootService", e);
}
// Start HomeActivity
try {
DUtils.caveman("BootReceive start HomeActivity....");
Intent startIntent = new Intent(context, HomeActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
} catch (Exception e) {
Log.e("BootReceiver", "Starting HomeActivity FAILED", e);
}
}
private void setDefaultLauncher(Context context) {
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context, HomeActivity.class);
Intent selectorIntent = new Intent(Intent.ACTION_MAIN);
selectorIntent.addCategory(Intent.CATEGORY_HOME);
selectorIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
selectorIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
selectorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Disable the default launcher (Android portal)
packageManager.setComponentEnabledSetting(
new ComponentName("com.google.android.tvlauncher", "com.google.android.tvlauncher.MainActivity"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
// Enable your app as the default launcher
packageManager.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
// Start the selector intent to make your app the default launcher
context.startActivity(selectorIntent);
}
}Вот мой манифест:
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/782 ... v-launcher