How to delete default Share App in Delphi code? - android

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)

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);

Prevent auto choose which sharing application use

I'm develop an application in Android.
I have a ListView with some image, when I click a row I open ContextMenu and I have two Choise, eliminate the image or sharing with other application.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri r = Util.getImageUri(getActivity().getApplication(), image);
intent.putExtra(Intent.EXTRA_STREAM, r);
startActivity(intent);
I use this code to sharing the image, but after the first time, every time that I try to share image, the application choose always the first application with wich I send the first image.
How can I prevent it?
I want that user choose every time sharing application.
Thanks.
t
I use this code to sharing the image, but after the first time, every time that I try to share image, the application choose always the first application with wich I send the first image.
That was because you indicated, to the chooser, that you wanted to make this choice "always", instead of "just once".
I want that user choose every time sharing application
Use:
startActivity(Intent.createChooser(intent, "..."));
where "..." is your explanation for this.
In your phone go to settings-->Apps then select the app which get opens by default then there you will find an option "Open by default" open that option, in there press "Clear Defaults".
Then in your app again you will get the list of application to share with

How to create shortcuts from other android apps

I am looking for a way to create shortcuts from other apps.
Like launchs can query the apps that allow to create shortcuts and create them save them in thier program.
My API version is between M(21) to N7.1(25).
Even just a link or name of API it's fine. I just couldn't find it at all. All I found is about the new shortcut in android N.
Thx for ur time.
I found the way to do it. Since i don't see much info for this. I hope my share can help whoever is also looking for the answer.
So there will be 3 steps:
Get apps that can create shortcuts
Send Intent to the app that you want to create shortcut from
Get shortcut data in Activity.onActivityResult
1.
Since I just need to create shortcuts from certain apps. I skipped step one. But I guess using queryIntentActivities(...) or some other functions in PackageManager can get you the list.
Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
PackageManager.queryIntentActitvies(intent,0);
2. Send intent to the app to create a shortcut.
Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
intent.setComponent(...);
startActivityForResult(intent, requestCode);
3. Get data of shortcut:
Shortcut intent
Intent shortcutIntent = activityResultIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
Shortcut name
String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Shortcut icon
Bitmap shortcutIcon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);

uninstall applications using a button click in android

In my application, I've developed to get a list of third party applications that the user installed. from that, what now I want is to add a button where, when clicked the user is directed to the inbuilt application details screen with the force stop and uninstall option, since I only take user installed application I don't need root permission and as well as system permission. is there a way to call that system intent inside my application.
try as:
Intent detailsIntent = new Intent();
detailsIntent.setClassName("com.android.settings",
"com.android.settings.InstalledAppDetails");
//ApiLevel greater than or equal to 8
detailsIntent.putExtra("pkg", "Appliction_Package_NAme");
//ApiLevel in less than 8
detailsIntent.putExtra("com.android.settings.ApplicationPkgName",
"Appliction_Package_NAme");
startActivity(detailsIntent);
try this
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:app package name"));
startActivity(intent);

How to open an album in Gallery app using an intent

Assuming I know that the Gallery has an album with a certain name X, what intent or broadcast can I make to open Album X with the Gallery app?
There are plenty of examples showing how to select a picture from the Gallery, but I don't see any describing how to accomplish the above.
Thanks.
try this
Intent intent = new Intent();
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Main.this.startActivity(intent);
program will browser all application are support with image file
but user can set default program
If you prepared the Gallery which is called X, yes you can do it.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.Xapp");
if (launchIntent != null) {
launchIntent.setData("PHOTO ID OR ANYTHING ELSE");
startActivity(launchIntent);
}
After then you can set data in intent. And X app parses intent data and you can open it.
Otherwise, you can't this action. You only call the app, If the application does not provide API support for send data with intent.

Categories

Resources