Reputation: 459
i want my app to autostart in vivo device but when i try to do so my app does not show in the list .Can anyone tell me how to resolve this error
i am already able to redirect to autostart activity of vivo
if (Build.BRAND.equalsIgnoreCase("vivo")) {
TITLE = "vivo device detected";
PACKAGE_NAME = "com.vivo.permissionmanager";
PACKAGE_ACITIVITY = "com.vivo.permissionmanager.activity.BgStartUpManagerActivity";
Intent intent = new Intent();
intent.setComponent(new ComponentName(
PACKAGE_NAME, PACKAGE_ACITIVITY));
startActivity(intent);
}
Upvotes: 4
Views: 517
Reputation: 147
This worked for me. It will work on 80% Chinese manufacturing devices
private void checkBatteryOptimization() {
Intent intent = new Intent();
String packageName = this.getPackageName();
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
}
this.startActivity(intent);
}
private void addAutoStartup() {
try {
Intent intent = new Intent();
String manufacturer = Build.MANUFACTURER;
if ("xiaomi".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
} else if ("oppo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
} else if ("vivo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
} else if ("Letv".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
} else if ("Honor".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
} else if ("oneplus".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"));
}
// case "oneplus":
// intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"));
// break;
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
startActivityForResult(intent, 9);
}
} catch (Exception e) {
Log.e("exc", String.valueOf(e));
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("test123 ee", "test " + requestCode + " " + resultCode + " " + data);
if (requestCode == 9) {
Intent mainIntent = new Intent(NotificationsActivity.this, MainActivity.class);
startActivity(mainIntent);
finish();
}
}
Upvotes: 0
Reputation: 54
//Please add this receiver in android manifest file
<receiver
android:name=".Boot_BroadCast"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
public class Boot_BroadCast extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
intent = new Intent(context, Clap_Service.class);
if (VERSION.SDK_INT >= 26) {
context.startForegroundService(intent)
}
}
}
Upvotes: 3