I want to update my android application programmatically.
I used following code:
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new
File(Environment.getExternalStorageDirectory()+"/AndroidTest.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This code display dialogue box to install application.
I want to install apk automatically.
Please help me.
Fortunately, this is not possible, for obvious security reasons. Apps cannot install apps without user intervention, with the exception of certain system apps that have the right permissions and such.
Yes It is possible Please check this out
For this you need SUPER_USERACCESS
Add this permission: <uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
Related
I am writing an Android launcher that does not support widgets, but it does support shortcuts. One of the shortcuts provided by AOSP is Direct dial, and my launcher needs the android.permission.CALL_PHONE permission for that. My question is, are there any other permissions that I need to add, to allow all possible shortcuts, even those provided by third party apps?
FOR NOUGAT SHORTCUTS ( API LEVEL 25+ )
There is not standard permission to add/launch shortcuts. If target api level of your app is 25+, you can use ShortcutManager or static shortcut via .xml meta-data.
https://developer.android.com/guide/topics/ui/shortcuts.html
FOR LEGACY SHORTCUTS ( BELOW API LEVEL 25 )
If you want to install&use Legacy shortcuts without user interaction, you need to declare INSTALL SHORTCUT permission.
Legacy shortcuts use Intent Action:
Create shortcut for Launcher: "android.intent.action.CREATE_SHORTCUT"
Install shortcut on Launcher: "com.android.launcher.action.INSTALL_SHORTCUT"
Required permission on AndroidManifest.xml:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
You can find more resources when you search for intent actions above.
There is no way to know this in advance. Some apps just assume that the caller of their shortcuts have some permissions (e.g. some system launcher shortcuts often only work in the system launcher itself, as they sometimes require some self defined permission).
In general, any app that offers shortcuts, should run the code in itself instead of the calling app to be sure the required permissions are present, but apparently this is not the case in some apps (especially in launchers e.g.).
I face this problem in an app of mine every now and then as well and catch the exception and tell the user, that the selected shortcut does not support other apps and is implemented in a wrong way.
Example - shortcut to call someone that works and that does not work
E.g. think about a third party app that offers a direct call shortcut. It can handle this in 2 way:
wrong way
It can return an intent like following:
Intent intent = new Intent();
Intent launchIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
...
This intent can ONLY be run by an app that has the action call permission
correct way
The app knows, that the caller may not have the call phone permission, so it does not return the direct phone call intent directly, but a custom one that it handles itself like e.g.
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.icon);
Intent intent = new Intent();
Intent launchIntent = new Intent(this, MyPhoneCallActivity.class);
launchIntent.putExtra("number", number);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(pause != null ? (pause ? R.string.shortcut_pause : R.string.shortcut_resume) : R.string.shortcut_toggle_pause_resume));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
If the caller executes the shortcut, the MyPhoneCallActivity will be started - this runs inside the app itself and has all permissions of the shortcut provider. This activity then can simply execute the Intent.ACTION_CALL intent itself and finishes itself afterwards. This way, the calling app does not need any special permissions. The workaround via an activity is one solution for this problem that works.
This is not a definitive answer, as I couldn't find this explicitly stated anywhere, but it seems that only phone call shortcuts require a permission, so the CALL_PHONE permission is the only one you need, to launch shortcuts.
AOSP launcher only checks for the CALL_PHONE permission. Source: https://android.googlesource.com/platform/packages/apps/Launcher3/+/master/src/com/android/launcher3/Launcher.java#1630
I haven't been able to find any other types of shortcuts that require permissions.
I want to enable floating notification using Android Code.Normally users didn't know about the setting. so i need to enable this as default.
Bad news I'm afraid.
As you probably are aware, this requires the permission SYSTEM_ALERT_WINDOW.
Since Android M google has begun locking down this permission to reduce clutter. What is a little unusual about this permission is it requires the user to go to an actual settings screen The ordinary Android M permission flow does not work for this. To quote the API:
If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen
You use the Settings class to check if you already have the permission and when you don't, you need to explain and direct the user to the relevant settings screen via intent:
Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + context.getPackageName()));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(i);
This should only ever affect devices running 23+ as older devices should get the permission automatically, but don't rely on checking SDK_INT, rely instead on canDrawOverlays, as there are exceptions for some pre-marshmallow devices
I was also facing same issue and need to enable it from settings but after adding permission in manifest file it worked perfectly.
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
Tested on version 9.
I struggled with that and found a way.
(In my case I'm using the OneSignal React-Native SDK)
The solution was to create a "category" (on the OneSignal console) that has the "urgent" importance :)
After that, when you send a push, you have to refer to the channel_id of this category.
Doc: https://documentation.onesignal.com/docs/android-notification-categories
I am trying to use UsageStatsManager. I know that I am supposed to include.
<user-permission android:label="PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions"/>.
I also started an intent for the user to allow usage access.
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
But my app does not show up in the Apps with usage access list in the settings.
Screenshot
I need to know why my app is not showing up in that list?
Your tag is misspelled. its supposed to be <uses-permission/> instead of <user-permission/> RIP
I am trying to use "android.permission.PACKAGE_USAGE_STATS" in my app. Here it says that NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.
It seems that I will need the user to explicitly give my app the permission to give access to the access the usage stats.
In addition, I used the intent code below to open the screen to allow user to give access to my app, but my app is not in the list.
Code I used:
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
When *startActivity(intent)' is fired (or going to *Settings>Security>Apps with Usage Access), a blank screen below pops up, my app is not part of it.
Bottom line question is -- How to use UsageStatsManager in Android Lollipop? Anyone tried it?
This is what worked for me.
<uses-permission xmlns:tools="http://schemas.android.com/tools"
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
You can simply make this on the manifest, ignoring just this permission error:
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions"/>
The AndroidManifest.xml error can be fixed by disabling lint errors. Specifically
Security - SignatureorSystemPermissions
I guess after that the settings app will show your app.
If I have two applications loaded on an Android device, are there calls I can make in one that will delete the other one? I am looking for something to delete apps in a fashion similar to how I can launch an app from another.
I thought this may be possible through the Intent/Activity interactions but it doesn't seem possible. This seems like something that may not be allowed for obvious reasons but wanted to check anyways.
Follow up question, can an application remove itself?
You cannot complete the removal without user approval, but you can use an intent to bring up a screen where they can confirm the removal:
<manifest ...>
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
...
</manifest>
Uri packageURI = Uri.parse("package:"+"some.package.to.remove");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
There are apps like quick uninstaller that speed up the delete process, you'll probably need to find an Intent that deletes the app, because the user still needs to have the final say over this.