Exceptions are not being caught in Android Studio when debugging - android

I have imported a project that was developed on Eclipse into Android Studio.
The project is working perfectly when running\debugging it from Eclipse on my device.
When debugging from the Android Studio on my device, the application is crashing and no exception is being caught on the Android Studio.
When I place breakpoints, they work fine, so I know i'm debugging the correct code :)
Edit:
I have run it again and got the following Exception in the logcat (shouldn't the debugger stop somewhere in the code to show the Exception? like in the line that tries to access the file?):
2018-10-24 11:25:26.027 25903-25903/? E/libpersona: Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
2018-10-24 11:25:31.735 23290-23301/? E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=25858, uid=10314 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:639)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:505)
at android.content.ContentProvider$Transport.query(ContentProvider.java:217)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
at android.os.Binder.execTransact(Binder.java:682)
Although I do have permissions set in the AndroidMenifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.eibimalul.smartgallery"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_SOCIAL_STREAM"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Edit 2: The Solution:
So apparently I was missing 2 things:
run-time permissions which I understood using this link here and with the help of #Pier Giorgio Misley's comment
I was missing permissions on the AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

The solution:
Apparently I was missing 2 things:
Run-time permissions which I understood using this link here and
with the help of #Pier Giorgio Misley's comment
I was missing permissions on the AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I am not sure if that's the right way to do it (answering my own question that is), since I got help from few developers here (#Pier Giorgio Misley in particular) in the comments only, but I thought it is important to mark the question as answered.

Related

Unknown <uses-permission android:name="TASKS"/> in AndroidManifest.xml?

I am opening an old Android Project and between the permissions in the AndroidManifest.xml I found this line: <uses-permission android:name="TASKS"/> but I can't recall what is the use for and sadly I can't find any documentation either.

java.lang.SecurityException despite INTERNET permission being in the manifest

I am getting the following error when I run my application on my phone:
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
I have already added that permission in my manifest file as follows:
<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I am getting the error only when I run the app on my phone. It runs fine on my GenyMotion emulator. I read similar questions on SO before posting it. Also, I have made a couple of apps before with same permissions, and this error had never occurred then. So I don't get why Android is messing it up this time.
P.S.: I updated my SDK tools before starting with this new application. Somehow felt that it was important to mention it!
Use small caps
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Figure out who is adding READ_PHONE_STATE to my manifest file?

I am compiling a project that does not explicitly request the READ_PHONE_STATE permission, but when I compile I am seeing the permission in my compiled Android Manifest file. I'm assuming some library that's being pulled in is adding it explicitly or forgot to set its minimum SDK version (which would add it).
The only thing I have to go on is that in the final manifest, the permissions I requested myself look like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And the READ_PHONE_STATE looks like this:
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
Does the android prefix mean anything?
Is there any way to narrow down which library is adding this permission?
You can exactly see if a (or because of) library adds some extra Permission to your manifest. Check at file generated (see below) during build process and look for the unwanted permission within the file!
Go to your project folder and look for this path:
[ProjectFolder]/build/outputs/logs/manifest-merger---report.txt
open the file and search for the permission
In my case I found these lines at the
uses-permission#android.permission.READ_PHONE_STATE IMPLIED from
C:\..\...\AppFolder\src\..\AndroidManifest.xml:2:1-14:12 reason:
com.some.evil.library has a targetSdkVersion < 4
This generated file show the output of the merge process described here in Android Developers site.
I would look at:
Android Library Manifest vs. App Manifest
This isn't really a duplicate so I won't flag, however I think he covers the topic fairly well in his answer to that question.
After that and assuming you can't figure it out, I would do the following:
Locate your gradle cache
Crack open the artifacts of each of your dependences (rename to .zip and extract is the easiest way to do this)
check if they have manifests included and see whats in the,

FlashBuilder adds INTERNET permission even though it is not in my APP XML when building APK

I have an Mobile AIR project in FlashBuilder 4.6(Using AIR 3.4) and I am having a real problem publishing an APK. Here is the section from my APP XML:
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>
]]></manifestAdditions>
For some reason, when I create an APK, the INTERNET permission is being tacked on the end of the manifest permissions block. Note that the application.xml in the asset/META-INF/AIR folder still looks correct.
Any ideas where I am going wrong?
After a lot more searching, I found my own answer:
Note: When you bundle the runtime, ADT adds the INTERNET and
BROADCAST_STICKY permissions to your application. These permissions
are required by the AIR runtime.
BROADCAST_STICKY seems to no longer be required, but apparently when using captive runtime we cannot get around this.

ACCESS_NETWORK_STATE permission on Android ICS

I declared the permission ACCESS_NETWORK_STATE in Application manifest as below.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Everything is good on Android 2.x. But on Android ICS, it failed with below log cat.
java.lang.SecurityException: ConnectivityService: Neither user 10093
nor current process has android.permission.ACCESS_NETWORK_STATE. at
android.os.Parcel.readException(Parcel.java:1327) at
android.os.Parcel.readException(Parcel.java:1281) at
android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:663)
at
android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:455)
at com.tapfortap.AdView.getNetwork(AdView.java:146) at
com.tapfortap.AdView.loadAdsWithAppId(AdView.java:133) at
com.tapfortap.AdView.access$100(AdView.java:47) at
com.tapfortap.AdView$1$1.run(AdView.java:88) at
android.os.Handler.handleCallback(Handler.java:605) at
android.os.Handler.dispatchMessage(Handler.java:92) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:4503) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) at
dalvik.system.NativeStart.main(Native Method)
I updated the permissions like this and it works.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
this is because ACCESS_NETWORK_STATE is used as connectivityManger and this needs INTERNET connection.
I believe this is an issue with Eclipse; it fails to refresh the manifest to load the permission.
I had the same problem as the original poster and solved it by adding the permission a second time--but then I was able to remove the permission without affecting behavior. This makes me suspect that Eclipse didn't load permissions correctly until I touched the file.
Just add the below permission and it will work fine, i had this a problem before and resolved with me
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
Clean and then Build project solved the issue for me.
Uh-oh,If u adding by default,it will be:
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE"/>
if u re-add permission by:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
It works fine.
Unbelievable ! It costs me 2 days
you are missing the Internet permission.add this permisssion it will correct your problem
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Just cut the <uses-permission android:name="android.permission.INTERNET" /> and paste all the above permissions. It will work fine...
Clean Project. Check the manifest file. Some package name changes or misplaced data may causes this error.
Clean the project will work.
In your code, There would be places where you would be checking the Internet Availability before making your calls so that your app doesn't crash at runtime. For that, you have to access the 'NETWORK STATE' which requires the permission :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And when the Internet is available, your device communicates with the server using the 'INTERNET' which requires the permission :
<uses-permission android:name="android.permission.INTERNET" />
In my case, neither Clean Project not Rebuild Project worked, and I spent hours to figure out how to get rid of this lint error.
I was also afraid to use the final option Invalidate Caches and Restart because I might roll back to any Local History of a file in future, in case any bug arises.
So finally, I opted for the following option.
I chose File->Invalidate Caches and Restart.
It opened a popup. I then selected the option Just Restart.
And guess what!!It solved my problem. So if any of you are still struggling to get rid of this error, you might wanna try my solution. Do let me know if it worked.

Categories

Resources