Comments (6)
Hey Travis! Thanks for reporting the issue. I will try to reproduce this and get back soon. Could you please also let me know which version of the library you tried with?
from android-permissions.
I tried quickly reproducing this with a Foreground service but was unable to. In my case, the prompt was displayed and when I granted/denied the permissions, I got the callbacks. I tried this on Pixel 3a API 29 Emulator
with library version 2.0.54
.
In case this behavior still occurs for you, please share the sample project. Also, mentioning which device/emulator you have been testing this on would help.
Thanks!
from android-permissions.
Hmm interesting... I was using Pixel 2 API 29
emulator also with version 2.0.54
. I'll try to make a small reproducible example.
from android-permissions.
Even after minifying my project, the issue persists. Maybe I'm doing something wrong, but I can't see what. In logcat I'm getting these logs from the plugin, so presumably, it's doing its job. Permissions are also granted properly, just the callbacks aren't being fired. No log and no Toast.
Here is the logcat output
2020-06-04 14:19:31.849 5178-5178/? V/GrantPermissionsActivity: Logged buttons presented and clicked permissionGroupName=android.permission-group.SMS uid=10140 package=org.company.MainActivity presentedButtons=25 clickedButton=8
2020-06-04 14:19:31.853 5178-5178/? V/GrantPermissionsActivity: Permission grant result requestId=-4786225859692112400 callingUid=10140 callingPackage=org.company.MainActivity permission=android.permission.SEND_SMS isImplicit=false result=6
This is my foreground service:
public class DetectionService extends Service {
private static String TAG = "DetectionService";
private static final String SERVICE_NOTIFICATION_CHANNEL = "Service Channel";
@Override
public void onDestroy() {
Log.d(TAG, "Service Stopped...");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (notificationManager != null) {
makeServiceNotificationChannel(notificationManager);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, SERVICE_NOTIFICATION_CHANNEL);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setSubText("Monitoring falls")
.build();
startForeground(110, notification);
}
}
Log.d(TAG, "Service started");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
checkPerms();
return START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) { return null; }
@RequiresApi(Build.VERSION_CODES.O)
private void makeServiceNotificationChannel(NotificationManager notificationManager){
String channelName = getResources().getString(R.string.app_name);
NotificationChannel channel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL,
channelName, NotificationManager.IMPORTANCE_HIGH);
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(channel);
}
@RequiresApi(Build.VERSION_CODES.M)
void checkPerms() {
if (checkSelfPermission(Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED
|| checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
!= PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "SMS Permissions not granted... requestng...");
PermissionManager permissionManager = PermissionManager.getInstance(this);
permissionManager.checkPermissions(
Arrays.asList(Manifest.permission.SEND_SMS, Manifest.permission.READ_PHONE_STATE),
new PermissionManager.PermissionRequestListener() {
@Override
public void onPermissionGranted() {
Log.d(TAG, "PERMISSION GRANTED");
Toast.makeText(getApplicationContext(),
"Permissions Granted", Toast.LENGTH_SHORT).show();
}
@Override
public void onPermissionDenied(DeniedPermissions deniedPermissions) {
Log.d(TAG, "PERMISSION DENIED");
Toast.makeText(getApplicationContext(),
"Denied: " + Arrays.toString(deniedPermissions.toArray()),
Toast.LENGTH_SHORT).show();
}
});
}
}
}
And this is my MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button monitorButton = findViewById(R.id.main_btn_monitor);
monitorButton.setOnClickListener((View v) -> {
Intent intent = new Intent(this, DetectionService.class);
startForegroundService(intent);
});
}
}
from android-permissions.
Hey @travisjayday!
I tried with the code that you have shared but I was still not able to reproduce the behavior. In my case, when the permissions were granted/denied, the callbacks were invoked. It worked fine for the notification flow as well when the permissions were asked when the service was in the background. It also worked fine for partial granting and denying.
I am not sure but maybe you are facing issues because of the lifecycle of the Activity or Service. Sharing your manifest file could help. At times setting the launchMode
could also cause issues. But to figure out the exact cause, I would really need some more details.
Thanks!
from android-permissions.
Sorry for the late response. I fixed the issue by just moving my permission checks to the main activity and communicating it from the service. BUT I also found out why it wasn't working earlier. The problem was that I was running the service on a different process. This is how my service was registered in AndroidManifest.xml
<service android:name=".services.DetectionService" android:process="com.somepackage"/>
Removing the android:process
attribute made the callbacks work.
from android-permissions.
Related Issues (20)
- How to grant multiple permissions at once in singleton place. HOT 1
- application@allowBack is required by the plugin HOT 5
- Can't add dependency HOT 2
- Question: Is this library published? HOT 3
- How do i test from Activity for onPermissionDenied() it cannot be invoked. i cannot make an object of PermissionHandler class HOT 3
- Notification channel not registered on API27 HOT 1
- New Location Permissions Scheme for Android Q HOT 5
- Switch to AndroidX HOT 2
- Logging occasional ConcurrentModificationException errors HOT 12
- error: Landroidx/localbroadcastmanager/content/LocalBroadcastManager, dependency missing HOT 1
- Using FLAG_ACTIVITY_NEW_TASK instead of notification
- Project should be moved off jcenter repository HOT 14
- NPE on runningAppProcesses iterator() in AppStatus.isInForeground() method HOT 7
- Crash when permissions denied HOT 3
- Api not adjusted to android-31 target. HOT 6
- [Updated] The library is still a live!! thank you @nishkarsh HOT 7
- Add ability to provide custom/app icon for the status bar notification HOT 2
- Allow using a high priority / important notification HOT 1
- Add ability to set color of notification HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-permissions.