Coder Social home page Coder Social logo

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? about ask HOT 10 CLOSED

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024
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?

from ask.

Comments (10)

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024 2

but when i deny any permission, app crashes with security exception. did i missed anything.?

from ask.

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024 1

It worked . nice.

from ask.

00ec454 avatar 00ec454 commented on July 26, 2024

here Ask.on(getApplicationContext()) pass activity reference Ask.on(this)

from ask.

00ec454 avatar 00ec454 commented on July 26, 2024

can you post the stacktrace?

from ask.

00ec454 avatar 00ec454 commented on July 26, 2024

btw, did you add the requested permissions in manifest file?

from ask.

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024
                                                                                  java.lang.RuntimeException: Unable to start receiver com.vistrav.ask.Ask$Receiver: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{c565248 17981:com.root5solutions.myapplication/u0a61} (pid=17981, uid=10061) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                      at android.app.ActivityThread.handleReceiver(ActivityThread.java:2732)
                                                                                      at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
                                                                                      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.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{c565248 17981:com.root5solutions.myapplication/u0a61} (pid=17981, uid=10061) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                      at android.os.Parcel.readException(Parcel.java:1599)
                                                                                      at android.os.Parcel.readException(Parcel.java:1552)
                                                                                      at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
                                                                                      at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
                                                                                      at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
                                                                                      at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
                                                                                      at android.content.ContentResolver.query(ContentResolver.java:475)
                                                                                      at android.content.ContentResolver.query(ContentResolver.java:434)
                                                                                      at com.root5solutions.myapplication.MainActivity$1.granted(MainActivity.java:48)
                                                                                      at com.vistrav.ask.Ask$Receiver.onReceive(Ask.java:87)
                                                                                      at android.app.ActivityThread.handleReceiver(ActivityThread.java:2725)
                                                                                      at android.app.ActivityThread.-wrap14(ActivityThread.java) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
                                                                                      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) 

from ask.

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024

My manifest

`

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

`

from ask.

00ec454 avatar 00ec454 commented on July 26, 2024

you need to add these requested permission into your AndroidManifest.xml file check here for examle

from ask.

rubinnellikunnathu avatar rubinnellikunnathu commented on July 26, 2024

no its not the problem. i think the problem is whenever i press deny permission button, it redirects to method void granted. there the code works without permission and finally endup in security exception (because permission is not given yet,but still it goes to granted method)

from ask.

00ec454 avatar 00ec454 commented on July 26, 2024

I know why
the method public void granted(List<String> permissions) will be called even if permission is denied but the list of permissions will be empty, you need to check what list if the desired permission has been granted by user, if yer the permission list will contain that permission else it will be in public void denied(List<String> permissions) permission list.
to avoid this error you need to put if condition in public void granted(List<String> permissions) and if particular permission granted then you can go ahead to check your logic. you can do something like

@Override
 public void granted(List<String> permissions) {
   if(permissions.contains(Manifest.permission.GET_ACCOUNTS)){
     // get account granted and put your logic here   
   }
   if(permissions.contains(Manifest.permission.READ_CONTACTS)){
     // CONTACTS granted and put your logic here   
   }
 }

from ask.

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.