GithubHelp home page GithubHelp logo

Comments (6)

nishkarsh avatar nishkarsh commented on August 15, 2024

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.

nishkarsh avatar nishkarsh commented on August 15, 2024

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.

travisjayday avatar travisjayday commented on August 15, 2024

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.

travisjayday avatar travisjayday commented on August 15, 2024

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.

nishkarsh avatar nishkarsh commented on August 15, 2024

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.

travisjayday avatar travisjayday commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.