How to open 'App Permissions' page in Settings programmatically in Android? - java

I know there is many question about it already.
But today I found this:
My phone is Gallaxy Note 4 and Samsung Gallery app works just as I want
'open App permissions page from Activity!' not setting-detail page.
Anyone knows how to do that?

Here is a method to open Settings > Permissions for your application:
public static void openPermissionSettings(Activity activity) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:" + activity.getPackageName()));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
}
You should consider using this when your permission is denied and shouldShowRequestPermissionRationale(Activity activity, String permission) returns true.

Related

How to run another app from my own app? For example, I want to run Facebook when i click on a button in my app

I want to run another app from my own app, for example i want to run Facebook when i click on a button in my app.
please notice that i am new to android development
Use intent :
Intent open_app = getPackageManager().getLaunchIntentForPackage("PACKAGE_NAME_ANOTHER_APP"); // like facebook package(com.facebook.katana)
if (open_app != null) {
startActivity(open_app); // Please check package name is there or not because it can throw NullPointerException
}
if you want to recommend any app from playstore to user on click button
do this :
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=PACKAGE_NAME_OF_APP"); like facebook (com.facebook.katana)
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

How to open particular activity using shortcut?

I am trying to open particular activity using shortcut but always run application.
When application is running in background and click on shortcut icon -> particular activity is open.
If application is killed from background then how to open particular activity using shortcut.
* Below method use for create shortcut
private void createShortcutOfApp() {
Intent shortcutIntent = new Intent(getApplicationContext(),
YourTargetActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "App shortcut name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.logo_of_your_app_shortcut));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate
getApplicationContext().sendBroadcast(addIntent);
}
permission in manifest
uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT
define in manifest
android:name=".YourTargetActivity"
android:exported="true"
I am tired to solve this problem, please help me.
Follw below link to know how to open particular activity on relaunch application.
It works for me.
How to make an android app return to the last open activity when relaunched?

Android open external IMDB application from my app

I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.

Android Sharing Intent only works with Google Photos, Crashes Other Apps [duplicate]

This question already has answers here:
Android ACTION_SEND event: "messaging failed to upload attachment"
(2 answers)
Closed 5 years ago.
I am trying to create a Sharing Intent for an Android App to share images to other apps. However, I'm getting this really weird result when implementing this feature.
I have a share button that when I click on the button, it runs the following method:
private void shareIntent() {
Uri currUri = Uri.parse(data.get(pos).getUrl());
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, currUri);
sharingIntent.setType("image/jpg");
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.share_to)));
}
data.get(pos).getUrl() returns the URL of a custom class I made that implements Parcelable, and when printing it out, it returns a directory like the following: "/storage/emulated/0/Pictures/primitive/Primitive-79538313.jpg"
The intent works at first, opening the sharing menu. However, when I click on most applications, it either crashes the application or it gives an error... except with Google Photos, which uploads the photo properly to the gallery.
Firstly, I'm wondering what I'm doing wrong to cause this issue in the other apps. Also, I'd like to know if someone has an explanation as to why only Google Photos allows the sharing feature to work, while many of the other apps I've tested do not.
For reference, here are some examples I've run with the sharing intent. When I try to share the image, it crashes Hangouts. It gives a "failed to load image" error message in Snapchat, "Unable to share file" in Slack and Gmail, "Upload was unsuccessful" in Drive, "Messenger was unable to process the file" in, well, Messenger, and "Couldn't load image" in GroupMe. It doesn't load the image in Facebook but doesn't crash nor give an error.
Thank you for any help or feedback you can provide!
EDIT:
This seemed to work without trying to get around App Permissions:
private void shareIntent() {
File imageFile = new File(data.get(pos).getUrl());
Uri uriToImage = FileProvider.getUriForFile(
this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(DetailActivity.this)
.setStream(uriToImage)
.getIntent();
shareIntent.setData(uriToImage);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Thank you to everyone that responded!
Change your code to this
private void shareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jepg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+data.get(pos).getUrl()));
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Add this code in your activity onCreate()
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

How to open Battery Use in About Device part of Settings Programatically in android?

i am developing an android app where i want to open the Battery use intent which is present in About device part of settings programatically. I am using the below code for it.
Intent i = new Intent();
i.setAction(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS);
startActivity(i);
The above code opens the About Device intent. But i want to open the Battery use option which is inside the About device part of Settings. Not getting how to do it. Please Help! Thanks!
Intent intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
startActivity(intentBatteryUsage);
Try this..
Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerUsageIntent, 0);
if(resolveInfo != null){
startActivity(powerUsageIntent);
}

Categories