How do I programmatically open energy saving settings in oppo device? - android

Hello I am trying to open energy savings settings of device oppo-CPH1609 for a specific application which looks like this.
Screenshot of settings screen.
I have tried following methods for doing it
Intent intent = new Intent();
intent.setAction(Settings.ACTION_BATTERY_SAVER_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
I have also tried to change action as
Settings.EXTRA_BATTERY_SAVER_MODE_ENABLED
Any Help would be appreciable.

You could do like below:
startActivityForResult(new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS),0);
//0 is request code
And in onActivityResult method, you could handle returned result.

Related

How to startActivity to accessibility settings page of my app in Android

This question is quite similar to other.
However there is still no solution.
I am using the below code to jump to the accessibility settings page.
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, REQUEST_USAGE_SETTING);
Instead of jump to main accessibility settings page, i would like to take the user to the settings page of my app.
for open setting page of your app you need to pass package name of your application as below,
try this it will redirect you to setting page of your application
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, 1);

How to delete default Share App in Delphi code?

I am creating an Android Application in Delphi, and I need a Button, which deletes the default Share App, if one is set.
E.g
I share a File via Gmail, and press 'Always'
The next time, this is the default app.
Is it possible to delete this in Code? Or can i open the App-Infos where it is possible to reset this option?
clearPackagePreferredActivities() in PackageManager will clear the defaults of a particular app, whichever's package name you pass.
(https://stackoverflow.com/a/13072877/6517492)
You can open the application settings screen programmatically. Java code:
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
intent.setData(uri);
context.startActivity(intent);
(from https://stackoverflow.com/a/35456817/6517492)

Whatsapp error Audio/Sound setResult intent

I have an app that can send a normal intent by calling startActivity with:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(filepath));
startActivity(sharingIntent);
But i want my app on whatsapp attach menu (Audio Item specifically) like this related discussion example: Returning an Image to whatsapp
So, i used the code below, my app is showed on menu but when i do the share steps i get whatsapp "Share failed, please try again" error message. Others similar apps do the steps with the final step showing the Whatsapp Recorder dialog to apply sound on chat.
On this second feature (whatsapp internal intent-filter sharing) i use the same intent but with this:
setResult(RESULT_OK, buildSoundShareIntent(soundId));
finish();
instead of startActivity
Is there something specific and hidden that i dont find?
The solution is below my noose all the time, its simple: call the Intent constructor with action and data (Uri.fromFile(File)):
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
setResult(sharingIntent);
In camera Settings; set storage to "Ext. SD card". Also, move any older photos you want to share to Ext. SD card. This worked perfectly with me. Hope it will work for you.

Intent.ACTION_CALL starts a skype call instead a "normal" phone call

I have the folowing code and im starting it from a dialog fragment button:
uri = "tel:"+ServerDialogCallUs.this.contents.getString("phone_number");
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
Instead of making a normal phone call this code starts a skype call. How can I give the user the option to chose between the normal call and a skype call.
Thanks
actually, i was missing the permission:
<uses-permission android:name="android.permission.CALL_PHONE" />
after adding this permission to the manifest I can chose between a normal and a skype call.
Thanks
Try to call setPackage() method, works fine:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
startActitivy(intent);
Had the same issue and tried some answers:
Intent.ACTION_CALL will call, which needs probably the right permission, BUT using Intent.ACTION_DIAL and use an Intent Chooser, I got the right behaviour.
Regarding USSD like "*123*03#" which pops up also as question in this context, where android says, it cannot handle the intent
2.1. Uri.encode("#") is not the solution, it just adds a "23" to the phone numer
2.2. Skype handles the number wrong, it adds the country-code like +001. So Skype does not handle USSDs correctly. But it seems, I have no chance, to exclude this.
So, I did:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.fromParts("tel", "123456", null));
startActivity(Intent.createChooser(intent, ""), REQUEST_CODE));
From my point of view
intent.setPackage("com.android.phone");
is device dependent or at least does not leave "phone" included on my device.
That's because
There is only skype installed as a phone call handler or
You associated skype as default handler for phone calls.
In the latter case, go to settings, apps, skype, and remove that association on the bottom of the app details screen.
Your phone probably has Skype as the default app to handle the Intent.ACTION_CALL
Try the following code:
uri = "tel:"+ServerDialogCallUs.this.contents.getString("phone_number");
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Call Using..."));

Pick an image from the Gallery

I have seen a lot of posts about this, and it seems like the code below should work. I have created an SD Card image and added it to the emulator (and that works fine).
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
//intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
It does launch and allow selection of images, but when I click on an image, everything exits and the emulator returns to the home screen, not the back to my app. My onActivityResult is never called either.
What am I missing?
I found my issue. I was launching the gallery from a sub-activity and that sub activity Intent had the flag FLAG_ACTIVITY_NO_HISTORY which prevented the call back from going to that activity.
thanks.
Use the following intent :
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);

Categories

Resources