00ec454 / ask Goto Github PK
View Code? Open in Web Editor NEWAndroid runtime permission make easy
Android runtime permission make easy
Seems like in the new update android 6.0.1 I cannot click allow,
Any ideas?
It would be great, if the Ask.on method also accepts android.app.Fragment and not only android.support.v4.app.Fragment.
It would be great if you add a Listener, which will be called if the library has asked for all permissions.
Something like this:
Ask.on(this)
.forPermissions(/* permisssions */)
.withRationales(/* rationales */)
.onFinished(new Ask.OnFinishedListener() {
@Override
public void onFinish() {
Log.i("Activity", "Asked for all permissions");
}
})
.go();
I just followed the steps mentioned in README file, when the user grants the permission the application needs to be restarted; as none of the buttons stay in workable state(don't know why!). After restart it works perfectly fine except one thing- there's a movement of an activity just before the app's launcher activity which is clearly visible sliding out of the screen..
Hi, when i am using Ask Library in my App, it is crashing, please find the details below.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.beyondseek.ServicesAroundMe/com.vistrav.ask.AskActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
at android.support.v7.app.AppCompatDelegateImplV7.onPostCreate(AppCompatDelegateImplV7.java:167)
at android.support.v7.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:98)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1188)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2398)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The code in the onCreate of my Permissions Activity:
Ask.on(PermissionAcitvity.this)
.forPermissions(Manifest.permission.ACCESS_COARSE_LOCATION
, Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CALL_PHONE,Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.MANAGE_DOCUMENTS,
Manifest.permission.CALL_PHONE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE)
.withRationales("Location permission need for map to work properly",
"In order to save file you will need to grant storage permission").go();
This is the App Theme that i am using:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
The compileSdkVersion is 24
And buildToolsVersion is '23.0.3'
Please help.
Hi!
When I try to record a test with Android Studio and Espresso UI, the clicks on the Permission dialog of ASK will NEVER be recorded and therefore never be replayed, so the test cannot start at all.
Is there a way to bypass it for tests only?
I found your library very useful and easy to integrate , but when i tried to integrate this into my app I wasn't able to show rational messages . so if you please care to help reply to this
and another thing when camera permission is given it doesn't shows multiple permission there
Great library, I really appreciate it but I am having a slight problem
When we call
Ask.on(this)
.forPermissions()
.go();
It is actually holding the reference to the activity in Ask.on()
, which is not garbage collected, what we can do about it?
Thanks
My logcat shows
Process: com.root5solutions.myapplication, PID: 12204 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.root5solutions.myapplication/com.root5solutions.myapplication.MainActivity}: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ContextImpl.startActivity(ContextImpl.java:672) at android.app.ContextImpl.startActivity(ContextImpl.java:659) at android.content.ContextWrapper.startActivity(ContextWrapper.java:331) at com.vistrav.ask.Ask.go(Ask.java:56) at com.root5solutions.myapplication.MainActivity.onCreate(MainActivity.java:104) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
i tried to access permissions such as READ_CONTACT
and GET_ACCOUNTS
by using the code below
import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.vistrav.ask.Ask;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "PM";
ArrayList<String> alName = new ArrayList<String>();
ArrayList<String> alContacts = new ArrayList<String>();
ArrayList<String> alEmails = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Ask.on(getApplicationContext())
.forPermissions(Manifest.permission.GET_ACCOUNTS
, Manifest.permission.READ_CONTACTS) //one or more permissions
.withRationales("Account permission need for app to work properly",
"Contact permission need for app to work properly") //optional
.when(new Ask.Permission() {
@Override
public void granted(List<String> permissions) {
try {
Account[] accounts = AccountManager.get(getApplicationContext()).getAccountsByType("com.google");
for (Account account : accounts) {
String emailid = account.name;
Log.e("account", emailid);
}
} catch (Exception e) {
Log.e("Exception", "Exception:" + e);
}
ContentResolver cr = getApplicationContext().getContentResolver(); //Activity/Application android.content.Context
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor.moveToFirst()) {
do {
String contactid = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{contactid}, null);
while (pCur.moveToNext()) {
String contactName = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
alContacts.add(contactNumber);
alName.add(contactName);
Log.e("Contact Name", contactName);
Log.e("Contact Number", contactNumber);
break;
}
pCur.close();
}
} while (cursor.moveToNext());
}
String emailIdOfContact = null;
cr = getApplicationContext().getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(BaseColumns._ID));
cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?", new String[]{id}, null);
Cursor emails = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + id, null, null);
while (emails.moveToNext()) {
emailIdOfContact = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
alEmails.add(emailIdOfContact);
Log.e("Email ID", emailIdOfContact);
}
emails.close();
}
}// end of contact name cursor
cur.close();
Log.e("ContactL Name", String.valueOf(alName));
Log.e("ContactL Number", String.valueOf(alContacts));
Log.e("ContactL Email", String.valueOf(alEmails));
Log.i(TAG, "granted :: " + permissions);
}
@Override
public void denied(List<String> permissions) {
Log.i(TAG, "denied :: " + permissions);
}
}).go();
}
}
i had created a dialog box manually ,if user denies the permission, here if user press cancel button the whole app will close and my question is ,if user clicks ok button , how will i reprompt the permission check.??
should i write the whole permission code once again..?
@Override
public void denied(List<String> permissions) {
showDialogOK("Get Accounts and Contact Permission required for this app",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
// permission check again
//but how
break;
case DialogInterface.BUTTON_NEGATIVE:
// proceed with logic by disabling the related features or quit the app.
finish();
break;
}
}
});
Log.i(TAG, "denied :: " + permissions);
}
}).go();
}
private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", okListener)
.setIcon(R.mipmap.ic_launcher)
.create()
.show();
}
First of all thanks for this lib - What I was actually looking for however I have one concern.
From the implementation based on Fragment
, I can see you used Fragment from
import android.app.Fragment
however all my fragments are based on the android support lib .i.e. android.support.v4.app.Fragment
.
Do you have any best way to handle this??
What the title says. When a user does not have permissions yet, the dialog shows up and accepts/denies the permission, after doing this, the app automatically closes for some reasons.
Using this pretty simple kotlin code:
Ask.on(this)
.id(1001)
.forPermissions(Manifest.permission.ACCESS_FINE_LOCATION)
.withRationales(getString(R.string.location_permission_rationale))
.go()
@AskGranted(Manifest.permission.ACCESS_FINE_LOCATION)
fun mapAccessGranted(id: Int) {
...
}
When running the app, permission is asked, but after OKing, mapAccessGranted is never called.
I have debugged the app and have found that, Ask.getAnnotatedMethod() gets called and seems to find the callback method OK, adding it to permissionMethodMapRef. So far so good.
However, when Ask.invokeMethod() is called, permissionMethodMapRef.get() is null, throwing the Exception at line 229.
Seems the WeakReference has been destroyed in the meantime.
Is this a kotlin specific issue? Any suggested workaround?
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed with multiple errors, see logs
with latest version support library
Has anyone found the issue with Android versions 8.0?
All the permission callbacks not working for Oneplus A300 running 8.0.
@00ec454 Sir , I was trying to implement your library for marshmallow permission it is working fine with multiple permissions, but when i give single permission, it shows the rational message twice although I have given only one permission and one rational message
plase disable rtl support in your manifest
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.