Feed Buzzard
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
Feed Buzzard
No Result
View All Result
Home World Tech

Android M request permission non activity –

Gordon James by Gordon James
January 15, 2021
in World Tech
0
0
SHARES
72
VIEWS
Share on FacebookShare on Twitter

Development issue/problem:

My widget makes calls to protect permissions outside the activity zone. Can I request outside permission for Android M?

How can I solve this problem?

Solution 1:

No, you can’t. You can send a notification where the user can click a button and then use the action to request/manage permission (possibly with a dialogue subject).

Solution 2:

You can use the Easy Resolutions library.

Android requires that these requests come from the company. With Easy Permissions this is no longer a problem, you can ask permission anywhere, as long as you provide the context. In addition, if you request an authorization that has already been granted, the user is not asked to request it.

Our company manages and develops this open access library. At the same time, we are sure that it is a useful tool that we would not otherwise pass on.

Solution 3:

I think you can request an off-site authorization if you use the method.

ActivityCompat.requestPermissions (Activity, String[] permissions, int requestCode)

of the support library and pass Activity as a method parameter.

For example:

ActivityCompat.requestPermissions(targetActivity, new String[] {Manifest.permission.CAMERA}, PERMISSION_REQUEST_CODE) ;

where the target activity is the activity that the method is intended to perform :

onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults)

This is the method that processes the outcome of the resolution request.

Solution 4:

You can only ask permission for an activity or an excerpt.

Define a point in the activity or fragment where you think the application needs authorization, and then call the requestPermission method. Sending a notification won’t work because your code needs to be processed until you get the requested permissions, then you continue your functionality with the onRequestPermissionResult() method.

Solution no. 5:

I have created an application that requires authorization control for many activities. So I created a static class that can be used globally in the application.
And it worked.
It worked for me.

I created a method to check the authorization request in another class like this.

The CheckForPermissions public class implements ActivityCompat.OnRequestPermissionsResultCallback {
private static final int MY_PERMISSIONS_REQUEST_READ_LOCATION = 1 ;

public static void checkForLocationPermissions(Activity context){if(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION))| ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED| ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_WARRANTED){ActivityCompat.requestPermissions(context,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_READ_LOCATION;)

}
}}

In my work, I called method.

CheckForPermissions.checkForLocationPermissions(this) ;

Solution no. 6:

I have come up with a solution that seems to work well. The trick is to create a transparent activity that only requires authorization and ends right after. There has to be a context, of course, but not necessarily an event.
An activity can return a result (granted or denied) by translation (since startActivtyForResult is not possible outside the activity).

You can use this activity:

import android.content.intent
import android.content.pm.PackageManager
import android.os.bundle
import android.support.v4.app.ActivActivity
import android.support.v7.app.AppCompatActivity

Internal constant KEY_PERMISSIONS_KEY = permissions
Internal constant GRANTED_PERMISSIONS_ACTION = GetPermissionsActivity.permissions_grantated
Internal constant DENIED_PERMISSIONS_ACTION = GetPermissionsActivity.permissions_denied

GetPermissionsActivity Course : AppCompatActivity() {.

permission privateValueRequestCode = 0

lift fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ActivityCompat.requestPermissions(
this,
intent.getStringArrayExtra(PERMISSIONS_KEY),
permissionRequestCode
)
}

Override fun onRequestPermissionsResult(
requestCode: Int,
permissions : Array,
grantResults : IntArray
) {
if (requestCode == permissionRequestCode) {
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.GUARANTEE_PERMISSION)) {
sendBroadcast(Intent(ACTION_PERMISSIONS_WARRANTED))
} else {
sendBroadcast(Intent(ACTION_PERMISSIONS_DENIED))
}
finish()
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}
}

And this style for the activity

In the manifesto:

And then use it like this (context required).

Some class: BroadcastReceiver() {

private fun someFunction(context: Context) {
val intentFilter = IntentFilter()
intentFilter.addAction(ACTION_PERMISSIONS_GENERATED)
intFilter.addAction(ACTION_PERMISSIONS_DENIED)
context.registerReceiver(this, intentFilter)
val intent = Intent(context, GetPermissionsActivity::class.java)
intent.putExtra(PERMISSIONS_KEY, arrayOf())
context.startActivity(intent)
}

Override fun onReceive(context:Context, intent:intent) {
when {
int.action == GARANTEED_PERMISSIONS_ACTION -> {
context.unregisterReceiver(this)
onPermissionsGranted()
}
intent.action == ACTION_PERMISSIONS_DENIED -> {
context.unregisterReceiver(this)
onPermissionsDenied()
}
else -> super.onReceive(context, intent)
}
}

privatepleasureonPermissionsGranted() {
// …
}

privatePermissionDenied() {
// …
}
}

Good luck!

Related Tags:

kotlin request permission, how to ask permission (runtime) again if the user deny for the first time, android request permission, android runtime permissions example github, android request permission in service, onrequestpermissionsresult, permission change listener android, multiple runtime permissions android example

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Gordon James

Gordon James

James Gordon is a content manager for the website Feedbuzzard. He loves spending time in nature, and his favorite pastime is watching dogs play. He also enjoys watching sunsets, as the colors are always so soothing to him. James loves learning about new technology, and he is excited to be working on a website that covers this topic.

Related Posts

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics
World Tech

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics

December 15, 2022
World Tech

Rockstar Games Brings GTA to The Metaverse

October 20, 2022
World Tech

Ways Technology Is Changing The World Of Education

September 21, 2022
Next Post

How To Install MongoDB In Windows + Compass GUI Admin

Windows Update won’t downloads or failed to install on windows 10 (Solved)

Discord Javascript Error “A fatal javascript error occured” [ Problem Solved ]

No Result
View All Result

Recommended

5 Useful Things You Can Do With cURL and Proxies

7 hours ago
Here’s Everything You Need to Know about Moles

Here’s Everything You Need to Know about Moles

3 days ago

Comic Play Casino Games

1 week ago

Here is a List of Some of the Most Interesting Slots You Can Play

1 week ago

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

Recent Posts

  • 5 Useful Things You Can Do With cURL and Proxies January 27, 2023
  • Here’s Everything You Need to Know about Moles January 25, 2023
  • Comic Play Casino Games January 20, 2023
  • Here is a List of Some of the Most Interesting Slots You Can Play January 20, 2023

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

© 2022 FeedBuzzard.com

No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT