开发者

need to know what package created/resumed my activity

开发者 https://www.devze.com 2023-03-13 17:04 出处:网络
I have an application that is secured with a password. Therefor i want the password dialog to show on all calls to onResume of any of my activities. The thing is that i do not want the password dialog

I have an application that is secured with a password. Therefor i want the password dialog to show on all calls to onResume of any of my activities. The thing is that i do not want the password dialog to show when navigating inside my own application.

So, i want to know if the application was entered from within or outside the application. What is the best way to accomplish this?

The only idea i have now is to use the getCallingActivity method and check if it contains my pac开发者_如何学JAVAkage name. The problem with this is that it forces me to use startActivityForResult() instead of just startActivity() wich is painful because i need to search all my code and change that.


Using the Android permission system, your protected activity can require a permission in order to be started. That permission would be defined in your manifest and it would be defined as requiring the same package signature to be granted.

The activity end users start would be the one that performs password verification; once it's satisfied it would start your protected activity. Attempts to start your protected activities by packages other than your own would fail.


From your inside code you could provide an extra field to the Intent that is used to start the Activity. Within the started Activity, check if this extra field exists and if so, you know the Activity was started by inside code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号