Android Things Bluetooth Le permissions - android-studio

I am trying to debug may Android Things BLE app in Android Studio. I am trying to do a simple scan on my main activity thread but I keep getting this exception:
01-17 02:13:24.735 29032-29044/com.dv.iotitag W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
at android.os.Parcel.readException(Parcel.java:2004)
at android.os.Parcel.readException(Parcel.java:1950)
at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:920)
at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onScannerRegistered(BluetoothLeScanner.java:442)
at android.bluetooth.le.IScannerCallback$Stub.onTransact(IScannerCallback.java:56)
at android.os.Binder.execTransact(Binder.java:697)
I have the permissions in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dv.iotitag">
<uses-feature android:name="android.hardware.bluetooth_le" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />
<uses-permission android:name="com.google.android.things.permission.MANAGE_BLUETOOTH" />
<application>
<uses-library android:name="com.google.android.things" />
<service
android:name="com.dv.androidthings.ble.common.BluetoothLeService"
android:enabled="true" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.IOT_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
but I still keep getting the exception in debug mode. What am I doing wrong?

From API 23 (Android 6.0) it is not sufficient to declare permisions in Manifest.xml. You have to request them in runtime as described here.

Go to your applications inside your phone and make sure your have location enabled and have it turned on.
In you oncreate method call:
checkPermission();
public void checkPermission() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
//
} else {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,}, 1);
}
}
}

Related

Error: Execution failed for task ':app:generateDebugBuildConfig'

I'm building an app that uses a Cordova plugin for Google Maps. I keep getting this error and have no clue how to fix it or what it even means. Any help would be appreciated. Here's the error:
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'.
> org.xml.sax.SAXParseException; systemId: file:/C:/Users/Amanda/Desktop/project2/platforms/android/app/src/main/AndroidManifest.xml; lineNumber: 5; columnNumber: 184; The prefix "tools" for attribute "tools:overrideLibrary" associated with an element type "application" is not bound.
And my AndroidManifest.xml:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.project2" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" tools:overrideLibrary="za.co.twyst">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="${GOOGLE_MAPS_ANDROID_API_KEY}" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.hardware.location" />
<uses-feature android:name="android.hardware.location.gps" />
</manifest>
Error
org.xml.sax.SAXParseException;
systemId: file:/C:/Users/Amanda/Desktop/project2/platforms/android/app/src/main/AndroidManifest.xml;
lineNumber: 5; columnNumber: 184;
The prefix "tools" for attribute "tools:overrideLibrary" associated with an element type "application" is not bound.
As you can see the error is in line no 5 and column no 184.As suggested i think you are missing the name space
xmlns:tools="http://schemas.android.com/tools"
Add this to your manifest so that your manifest will look something like this
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true"
android:versionCode="10000"
android:versionName="1.0.0"
package="com.example.project2"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" tools:overrideLibrary="za.co.twyst">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="${GOOGLE_MAPS_ANDROID_API_KEY}" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.hardware.location" />
<uses-feature android:name="android.hardware.location.gps" />
</manifest>

Cause: duplicate entry: AndroidManifest.xml

I'm using a project downloaded from codecanyon.net, the project fails Gradle build with an error message. I tried reviewing other questions with a similar issue but none worked for me. Please anybody can help me fix this issue
Cause: duplicate entry: AndroidManifest.xml
Below is the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.dreams.chat">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name=".BaseApplication"
android:allowBackup="false"
android:appComponentFactory="whateverString"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_logo_"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:allowBackup,android:appComponentFactory">
<activity
android:name=".activities.MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".activities.ChatActivity"
android:parentActivityName=".activities.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<!--android:windowSoftInputMode="stateHidden|adjustResize|adjustPan">-->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
<activity android:name=".activities.ImageViewerActivity" />
<service
android:name=".services.FirebaseChatService"
android:enabled="true" />
<service android:name=".services.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver
android:name=".receivers.ConnectivityReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"
tools:ignore="BatteryLife" />
</intent-filter>
</receiver>
<!-- https://developers.google.com/places/android-sdk/signup -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<provider
android:name=".utils.MyFileProvider"
android:authorities="#string/authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
<activity
android:name=".activities.ContactViewerActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".activities.ChatDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".activities.SignInActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoTitle"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".activities.CallScreenActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activities.IncomingCallScreenActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activities.SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoTitle"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".services.FetchMyUsersService"
android:exported="false" />
<service
android:name=".services.SinchService"
android:enabled="true"
android:exported="false" />
<activity
android:name=".activities.ChooseSignInActivity"
android:label="#string/title_activity_choose_sign_in"
android:theme="#style/AppTheme" />
<activity
android:name=".activities.ContactActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".activities.PrivacyPolicyActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<meta-data
android:name="com.dreams.chat.status.glideProgressBar.OkHttpProgressGlideModule"
android:value="GlideModule" />
<activity
android:name=".activities.StatusStoriesActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/FullScreenVideoTheme" />
<activity
android:name=".activities.CallListActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" />
</application>
</manifest>
and this is the excception detailed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugAssets'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform timezago-1.1.8.aar (com.chootdev:timezago:1.1.8) to match attributes {artifactType=android-assets, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: C:\Users\JRAR\.gradle\caches\modules-2\files-2.1\com.chootdev\timezago\1.1.8\a988a24719cbe07115df73a045aa251630cdb10\timezago-1.1.8.aar.
> Failed to transform 'C:\Users\JRAR\.gradle\caches\modules-2\files-2.1\com.chootdev\timezago\1.1.8\a988a24719cbe07115df73a045aa251630cdb10\timezago-1.1.8.aar' using Jetifier. Reason: ZipException, message: duplicate entry: AndroidManifest.xml. (Run with --stacktrace for more details.)
Please file a bug at http://issuetracker.google.com/issues/new?component=460323.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings
The issue was with allowbackup and appComponentFactory. I found lead to my solution in this question, if logs and build is not providing enough details about the issue, do check merged manifest it show errors with suggestions.
Open application manifest (AndroidManifest.xml) and click on Merged Manifest (in bottom) see image below.

My App keep crashing and display "app has stopped working" I dont understand the trace in logcat

This is the manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".Map"
android:label="#string/title_activity_map">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This app is suppose to find nearby places but whenever i click the button to search nearby places, it crashes
This is the logcat image but i dont understand

Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]!

So I am doing a little something in Android and this error comes up:
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
I cant install the app please help! My AndroidManifest is follow: Please have a look and help me!
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22" />
<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" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18"
/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<meta-data
android:name="android.app.searchable"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
== <meta-data
android:name="android.app.searchable"/>
</activity>
</application>
My bad I had not added the Name-Value pair for Meta Data (Value part) so the meta data had only Name and no values. When I deleted all the meta datas I resolved it for now.
Thanks

java.net.SocketException:socketfailed:EACCES(permission denied) for OTP application in Android Studio

I am trying to create an One time password access android application. I have created a local host server using wamp and I am trying to access that thing with the mobile application I have designed. Unfortunately, I am getting the error as following in my log cat:
03-07 10:42:35.097 31217-31217/com.example.user.myapplication V/ActivityThread: updateVisibility : ActivityRecord{1ecab2fb token=android.os.BinderProxy#23c38b5b {com.example.user.myapplication/com.example.user.myapplication.activity.SmsActivity}} show : true
03-07 10:42:36.607 31217-31217/com.example.user.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#23c38b5b time:52633449
03-07 10:42:37.397 31217-31217/com.example.user.myapplication D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
03-07 10:42:37.537 31217-32544/com.example.user.myapplication E/SmsActivity: Posting params: {email=thomasbi#gmail.com, name=Thomas, mobile=9002378900}
03-07 10:42:37.537 31217-32544/com.example.user.myapplication I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-07 10:42:37.537 31217-32544/com.example.user.myapplication I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
03-07 10:42:37.547 31217-31217/com.example.user.myapplication E/SmsActivity: Error: java.net.SocketException: socket failed: EACCES (Permission denied)
03-07 10:42:37.617 31217-31217/com.example.user.myapplication D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered!
I have included all of the permissions, here's my AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<application
android:name=".app.MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<activity
android:name=".activity.SmsActivity"
android:label="#string/title_activity_sms">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize">
</activity>
<!-- SMS Receiver -->
<receiver android:name=".receiver.SmsReceiver">
<intent-filter android:priority="99999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<!-- Intent service -->
<service
android:name=".service.HttpService"
android:exported="false" />
</application>
I am bit confused at the moment and I understand I am stuck with something silly. I would be deeply obliged if anyone could help me with the issue.
If you are targeting API 23+ (Marshmallow), permission requests are made when a permission is required, not doing so can result in an unwanted user experience.
This site has a good explanation and examples:
http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal

Resources