There's no possibility to open preview of screensaver like for a live wallpaper so I'd like to provide a shortcut for users to open TV's settings and manually set screensaver.
Currently I open system settings with intent action android.settings.SETTINGS which opens root device settings.
On phones I can start android.settings.DREAM_SETTINGS (it is described in docs here) which opens corresponding settings section. But this doesn't work on TV (tried on emulator). Is it possible to open it on Android TV?
Just in case somebody looks for launching screensaver on Nvidia Shield.
The intent name is com.android.systemui/.Somnambulator.
If using Button Mapper app, use "Broadcase Intent" with "Package": com.android.systemui and "Component": com.android.systemui.Somnambulator.
I've found a way to launch this activity in the source code of "Aerial Dream" screensaver: https://github.com/cachapa/AerialDream/blob/master/app/src/main/java/com/codingbuffalo/aerialdream/SettingsFragment.java#L29
// Check if the daydream intent is available - some devices (e.g. NVidia Shield) do not support it
Intent intent = new Intent(SCREENSAVER_SETTINGS);
if (!intentAvailable(intent)) {
// Try opening the daydream settings activity directly: https://gist.github.com/reines/bc798a2cb539f51877bb279125092104
intent = new Intent(Intent.ACTION_MAIN).setClassName("com.android.tv.settings", "com.android.tv.settings.device.display.daydream.DaydreamActivity");
if (!intentAvailable(intent)) {
// If all else fails, open the normal settings screen
intent = new Intent(SETTINGS);
}
}
startActivity(intent);
private boolean intentAvailable(Intent intent) {
PackageManager manager = getActivity().getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
return !infos.isEmpty();
}
Related
Notification sound settings always disable in Xiomi devices. Check below image.
I want to enable sound programatically. Found similar stackoverflow questions but nothing helped.
Device : Redmi Note 5 pro, Redmi Note 9 pro
OS : MIUI 11 , MIUI 12
Note: But it works fine in all other devices. Problem only in Xiomi devices
I was looking for the same kind of issue 2 months ago, due to restrictions by Xiaomi it has become a lot harder, basically you have to have your app running without restriction in save battery settings and to bring the user to autostart where he will have to click on the toggle button to add your app.
Prompt the user to disable battery optimization for your app:
public class MainActivity extends AppCompatActivity {
#Override
protected void onStart()
{
String packageName = "com.example.myapp";
PowerManager powerManager = (PowerManager)getApplicationContext().getSystemService(POWER_SERVICE);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent i = new Intent();
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
i.setData(Uri.parse("package:" + packageName));
startActivity(i);
}
}
}
}
For an app to use this, it also must hold the Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission
You also have to prompt the user to add your app to autostart (original credit) :
String manufacturer = "xiaomi";
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
//this will open auto start screen where user can enable permission for your app
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent1);
}
It should now be working, let me know if it helped!
You may try to use NotificationManager.IMPORTANCE_MAX in new NotificationChannel
I want to change my android device audio mode from Normal to silent and silent to normal. `
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if(!silent) {
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
silent = true;
}
else {
audio.setRingerMode( AudioManager.RINGER_MODE_VIBRATE );
silent = false;
}
`
This is my code that i'm using. Perfectly running until Android 6 all versions.
But on Android 7+ it crashes.
I found a solution on web that opens a settings intent and get some permission from user then this code works fine. It is the code i used then
Intent intent = new Intent(
android.provider.Settings
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
But my project requirement is don't request to open a setting intent to allow it form there. Is should be work like getting user permission to change mode on same activity just like all other permissions i.e. location, read contacts etc.
I tried to find out the find how they implement the permission in the code file but did not find it. Please let me know if anyone know.
This is the only way to change the Audio Mode of Android with api level > 23
Intent intent = new Intent(
android.provider.Settings
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
Now officially its released by Android to get user permission to access Notification Policy of device to change the audio Mode.
I would like to perform network providers search on my dual SIM device.
So far I've been doing so by opening the "Available networks" or the "Network operators" menu item in the "Network settings" page.
I've been doing it using this intent:
intent.setComponent(ComponentName.unflattenFromString("com.android.phone/.NetworkSetting"));
This opened the right activity directly, and automatically started searching for the available networks.
However, I'm on a dual SIM device right now, and whenever I open that activity by the intent above, It is opened on the "SIM2" tab of the activity, and hence I receive an error searching for available networks (SIM2 is empty, but it doesn't matter, because I want that functionality for SIM1).
Is there any way to select which SIM to open the activity under? or a proper way to open the needed activity for searching networks on the main SIM?
I have been searching and it's not a very common thing, so nothing was found actually.
This code works for my China A918 DualSim Android Phone:
Intent intent = new Intent();
intent.setClassName("com.android.phone", "com.mediatek.settings.MultipleSimActivity");
PackageManager packageManager = getPackageManager();
// check if intent is available on device:
List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
// set Intent to start after SIM card selection:
intent.putExtra("TARGET_CLASS", "com.android.phone.NetworkSetting");
intent.putExtra("ITEM_TYPE", "PreferenceScreen");
} else {
// run default android network settings intent
intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting");
}
startActivity(intent);
In Android DualSim Phones you need to run different Intent to enter NetworkSettings, because when two SIM cards are inserted, you should have ability to choose first or second card.
In my case this is com.mediatek.settings.MultipleSimActivity. If it wont work, check in ADB logs which Intent is started when enter in "Available networks" through android system Setting
The issue is that I need to install an apk(non market app) and for this, the user need to activate the unknown source setting, so i send him (if he didn't have it activated) to the settings so he can turn on the option, the issue is that i tested it in different phones and in samsung that option is on applications while in htcs phones is on security. i want send the user to that option but i don't know how to do it
I read about this and no one knows exactly how to do it
this is my code
int canInstallFromOtherSources = Settings.Secure.getInt(ctx2,Settings.Secure.INSTALL_NON_MARKET_APPS);
if(canInstallFromOtherSources == 0)
{
Intent intentSettings = new Intent();
intentSettings.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intentSettings);
}
You can do it with the following line (changing to the corresponding action):
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_CODE_ENABLE_LOCATION_PROVIDERS);
Check Android Settings documentation.
I think you should use ACTION_SECURITY_SETTINGS and one of ACTION_APPLICATION_SETTINGS or ACTION_APPLICATION_DEVELOPMENT_SETTINGS.
And here (line 304), you've got a working example of one of my apps: Tureame
Is there any differences between M100S and M110S?
My app uses camera component. codes are as follows
{
ComponentName compName = new ComponentName("com.android.camera", "com.android.camera.Camera");
Intent camIntent = new Intent(Intent.ACTION_MAIN);
actIntent.addCategory(Intent.CATEGORY_LAUNCHER);
actIntent.setComponent(compName);
StartActivity(actIntent);
}
it works in M100S but not in M110S.
In M110S, app is crashed.
So I wonder if app is crashed because of the difference between the devices
or my codes are wrong.
Any idea?
package name is changed.
com.android.camera -> com.sec.android.app.camera
I checked it in logcat msg.
I'm not sure it is under specification of android.