The app closes due to getting permissions without any error messages - android

My application is closed immediately after launching due permission request without an errors. This is my code, is here something wrong? Also, I post manifest file here to let you check it. I need bluetooth permission and data access.
The probem is in this line:
ActivityCompat.requestPermissions(this, permissions, REQUEST_MICROPHONE);
If I comment this, application will not close after launching.
private static final int REQUEST_MICROPHONE = 1;
private void askPermissions(){
String[] permissions = {Manifest.permission.RECORD_AUDIO,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT};
if (!hasPermissions(permissions)) {
ActivityCompat.requestPermissions(this, permissions, REQUEST_MICROPHONE);
}
}
private boolean hasPermissions(String[] permissions) {
if(permissions != null){
for(String perm : permissions){
if(ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED)
return false;
}}
return true;
}
And the Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-sdk android:minSdkVersion="21"
android:targetSdkVersion="30"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- If you want to declare that your app is available to BLE-capable devices only, include the following in your app's manifest:/-->
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:configChanges="orientation|screenSize"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="#style/Theme.myapp">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.myapp.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

It was discrepancy between Android version and way to get permissions. Unfortunately, it was not any errors or other communications and I have to find a problem by luck.

Related

Load WebExtensions on GeckoView

I'm working with GeckoView and met problem with installing AddOns. As suggested on Documentation, I've provided XPI compatible with Android, but nothing changes. Copying file to Assets doesn't make a change. Browser doesn't acknowledge WebExtension.
private fun setupGeckoView() {
geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
override fun onContentPermissionRequest(
session: GeckoSession,
perm: GeckoSession.PermissionDelegate.ContentPermission
): GeckoResult<Int>? {
return super.onContentPermissionRequest(session, perm)
}
}
geckoView = findViewById(R.id.geckoView)
val runtime = GeckoRuntime.create(this)
runtime.settings.consoleOutputEnabled = true
runtime.webExtensionController.promptDelegate = PromptListener(runtime.webExtensionController)
runtime.webExtensionController
.install("https://addons.mozilla.org/android/downloads/file/3719055/youtube_high_definition-85.0.0-an+fx.xpi")
geckoSession.open(runtime)
geckoView.setSession(geckoSession)
geckoSession.loadUri("https://www.youtube.com")
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gv.webapp">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.webapp">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--<provider
android:authorities="com.gv.webapp"
android:name="com.gv.webapp.Provider">
<grant-uri-permission android:path="string"
android:pathPattern="string"
android:pathPrefix="string" />
</provider>-->
</application>
</manifest>
I'm checking logs and the result is confusing. I've got prompt that WebExtension is installed, but when I looking at controller.list() it's empty.
You may be missing a PermissionDelegate:
geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
override fun onContentPermissionRequest(
session: GeckoSession,
perm: GeckoSession.PermissionDelegate.ContentPermission
): GeckoResult<Int>? {
return super.onContentPermissionRequest(session, perm)
}
}
Permission delegate allows you to handle requests from Gecko for any permission that needs handling.

my app doesn't asks permission at the time of downloading from google play store.I have specified location permission in my manifest file

Mainifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/hero3"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="info.food360.nikhil.splash"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="info.food360.nikhil.MainActivity"
android:windowSoftInputMode="adjustPan|adjustResize"
android:theme="#style/AppTheme.NoActionBar"/>
<activity
android:name="info.food360.nikhil.DesActivity"
android:configChanges="orientation|screenSize"
android:label="DestinationActivity" />
<activity android:name="info.food360.nikhil.Suggestion" />
<activity android:name="info.food360.nikhil.LocationWork" />
<activity android:name="info.food360.nikhil.logicBehind"></activity>
</application>
my app need location permission I thought google play store would ask at the time of downloading but user have to set location manually.what is the way that google play store should ask what should I add in my code?
If you're running in the android API version 23 or higher you'll need to require permissions at runtime. To ask for permissions you should do it right before using the feature that uses the permission:
int MY_PERMISSIONS_REQUEST_LOCATION = 123;
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
//app doesn't have permission yet
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
} else {
// Permission has already been granted
}
Then override the onRequestPermissionsResult to see if the user has given the permission:
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_LOCATION: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
} else {
// permission denied
}
return;
}
}
}

App has stopped when run a service in different thread

I added android:process in manifest file, and then i get app has stopped popup while loading up apk. Service doesn't load but the rest of thing is running okay.
<service
android:name=".smsReceiveService"
android:exported="true"
android:enabled="true"
android:process=":myProcess"
android:isolatedProcess="true"
android:permission="android.permission.RECEIVE_SMS" />
add permission in manifiest file at top
like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ncrypted.otp">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"/>
than your receiver sevrcice in application tag like this
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
than handle run time permision for lolipop virsions like this
private void requestSmsPermission() {
String permission = Manifest.permission.READ_SMS;
int grant = ContextCompat.checkSelfPermission(this, permission);
if (grant != PackageManager.PERMISSION_GRANTED) {
String[] permission_list = new String[1];
permission_list[0] = permission;
ActivityCompat.requestPermissions(this, permission_list, 1);
}
}

Unable to access permission(s) within java code from manifest

manifest.java :
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mfi;
public final class Manifest {
public static final class permission {
public static final String C2D_MESSAGE="permission.C2D_MESSAGE";
}
}
AndroidManifest.xml :
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GPS_PROVIDER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
But I'm unable to request any permissions from MainActivity as below code throws compiler error L: cannot resolve symbol : ACCESS_FINE_LOCATION
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
1);
How to update manifest.java to generate the permission I'm attempting to access, in this case Manifest.permission.ACCESS_FINE_LOCATION ?
Import the below package for Manifest class,
import android.Manifest;
You can easily access the permission Manifest.permission.ACCESS_FINE_LOCATION and others too

Android permission dialog not displaying

I have found a few other questions about this issue but none of the answers have solved it for me. I'm trying to request the fine location permission, but there is no dialog shown. Here's what I'm doing:
int permissionCheck = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION);
if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
Log.d("Location","Location permission already granted"); // Not logged
// Do other stuff
}
else {
Log.d("Location", "Requesting location permission"); // This is logged
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_ENABLE_LOCATION);
}
No dialog appears, and onRequestPermissionsResult is not called.
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.common" android:installLocation="auto">
<!-- Normal permissions -->
<uses-permission android:name="android.permission.ACCESS_GPS" android:required="false"/>
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" android:required="false" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" >
</supports-screens>
<application
android:name="com.company.common.App"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="AA_DB_NAME" android:value="propertyforce.db" />
<meta-data android:name="AA_DB_VERSION" android:value="11" />
<meta-data android:name="AA_SERIALIZERS"
android:value="com.company.common.utils.db.JSONObjectSerializer,
com.company.common.utils.db.JSONArraySerializer,
com.company.common.utils.db.AddressSerializer" />
<meta-data
android:name="AA_MODELS"
android:value="com.company.common.utils.db.Model" />
<activity
android:name="com.company.common.Name"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_label"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.AnActivity"/>
<!-- Other activities -->
<service
android:name="com.company.common.utils.services.LogDeleter"
android:icon="#drawable/icon"
android:label="Log Deleter" >
</service>
</application>
</manifest>
Here are some tidbits from the gradle file:
compileSdkVersion 23
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 12
targetSdkVersion 23
}
This is in a FragmentActivity, don't know if that matters. I have uninstalled the app and run it so there should be no permissions already accepted. This is on a Nexus 7 running 6.0.
Why not try this library: https://github.com/tajchert/Nammu. It worked for me.
Nammu.askForPermission(activity, String[] permissions, new PermissionCallback() {
#Override
public void permissionGranted() {}
#Override
public void permissionRefused() {}
});
EDIT
I created a library that encapsulates the whole thing and makes it much more easier. It also shows a customisable explanation dialog before the actual request.
Use this library: https://github.com/ayz4sci/permissionHelper
Usage:
To perform an action that requires Android permission, call permissionHelper.verifyPermission. It accepts the following parameters:
String [] - description of each permission required, this will be displayed to the user in the explanation dialog.
String [] - an array of Manifest permissions
PermissionCallback - you put the actions you want to perform when permission is granted or rejected.
See example below:
permissionHelper.verifyPermission(
new String[]{"dial this number", "take picture"},
new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.CAMERA},
new PermissionCallback() {
#Override
public void permissionGranted() {
//action to perform when permission granteed
}
#Override
public void permissionRefused() {
//action to perform when permission refused
}
}
);

Categories

Resources