Install apk from java code without user confirmation - android

I want to install an apk file from java code. I want to do this silently without any action from user. I try this code ..
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(files[i].toString())), "application/vnd.android.package-archive");
startActivity(intent);
It works but wants the user to confirm the installation.
I try
Process p;
p = Runtime.getRuntime().exec("pm -s install "+files[i].toString()+"\"");
but doesn't work
i have given these permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />

Related

how to give dynamic android.permission.WRITE_SETTINGS permission on a board non UserInterface

I have installed application as a user mode and not rooted. Hence some of the android.permissions like write permission are ignored and not set. was able to identify from packages.xml and also from the command "adb shell dumpsys package "
I want to set write permission to the application that I installed to the device.
I have access to android OS code, Is there a way to grant the permission? either by sepolicy change??
Note : device is not UI(user interface)
Please help!!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=<package-name>
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application android:label="#string/app_name" >
<service android:name=<service-name>
<intent-filter >
---
</intent-filter>
</service>
</application>
</manifest>
On a rooted device you can use the following command:
adb shell appops set foo.bar.package WRITE_SETTINGS allow
use this command adb shell pm grant you package android.permission.WRITE_SECURE_SETTINGS and only system app and rooted app can write the setting but this command help you to write setting.
public void setSettingsAutomaticDateTimeIfNeeded() {
String timeZoneSettings = android.provider.Settings.Global.getString(
this.getContentResolver(),
android.provider.Settings.Global.AUTO_TIME_ZONE);
Log.e(TAG, "auot update check true");
if (timeZoneSettings.contentEquals("0")) {
android.provider.Settings.Global.putString(
this.getContentResolver(),
Settings.Global.AUTO_TIME_ZONE, "1");
Log.e(TAG, "Auto update checked make true");
}
String timeSettings = android.provider.Settings.Global.getString(
this.getContentResolver(),
android.provider.Settings.Global.AUTO_TIME);
Log.e(TAG, "auot update check true");
if (timeSettings.contentEquals("0")) {
android.provider.Settings.Global.putString(
this.getContentResolver(),
Settings.Global.AUTO_TIME, "1");
Log.e(TAG, "Auto update checked make true");
}
}
and add this inot manifest
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />

Flutter - pick and upload image work while debugging and don't work in apk app-release

My app should take an image from gallery and upload it to server and show it.
To pick the image I used:
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
To upload it I used:
String uploadedImageUrl = await AmazonS3Cognito.upload(....);
Picking image is working in debug, but not working when I build an APK!
I thought the problem is in Android Manifest,
My Manifest file is hovered with yellow color and show this message:
And above <application...> ... </application> I add those permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
But I still have the problem with the release version.

How to sharea file from Android app to other device via bluetooth?

Hi,
I'm developing an app on android studio that allows me to send a txt file, which I create from the EditText, to another device via Bluetooth, my code is this:
Intent intent=new Intent(Intent.ACTION_SEND);
Uri text=Uri.parse(Environment.getExternalStorageDirectory().toString()+"/doc/mytext.txt");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, text);
startActivity(Intent.createChooser(intent,BLUETOOTH_SERVICE));
I can share the file via whatsapp without problems but via bluetooth I have the following errors:
[
on:
Bluetooth file sent:
Successful operations: 0, Non-tripping operations: 4.
under:
Bluetooth: file Unknown file not sent]1
unknown file
Laptop ..
The request could not be correctly managed.
I have set the following permissions on the Android Manifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

No permission to write on android emulator

I have been trying to download a file from a url.
I have set the permissions in my android manifest file like so,
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I am using a library called Adavnced WebView to handle downloads:
AdvancedWebView.handleDownload(view.getContext(),"https://static1.squarespace.com/static/57752cbed1758e541bdeef6b/t/58d91311ff7c50b172946ee5/1490621221735/PreKGuide_2017_English_032417+%281%29.pdf" , "abc.txt");
I get an error when I try to download. It clearly says that the app doesn't have permission to write to storage path. How can I set permission to write? What am I missing here? Please help.
java.lang.SecurityException: No permission to write to /storage/emulated/0/Download/abc.txt: Neither user 10147 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.
You need the runtime permission, check the documentation.

Why my app requesting media permission when installing?

I released my application in Google Play and when trying to install it it requesting access to Media although I didn't set that in the Manifest file
Here are my permissions in the Manifest file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
when in installing my app from the phone it asks from media access:
but when I open my app in the desktop browser it doesn’t show Media permission with the other permissions:
There was android.permission.WRITE_EXTERNAL_STORAGE permission in my app but i removed it and updated my app yesterday but Google Play still requesting Media access when trying to install it so i cleared Google Play's cache and tried again and now it doesn't request that permission any more . Thank you

Categories

Resources