How to get My Location in google Map using GPS? - java

I am traying to use mMap.setMyLocationEnabled(true); to get my position using GPS but I found this error :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test_app, PID: 19982 java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
How to fix it ?
public void onMapReady (GoogleMap googleMap){
mMap = googleMap;
mMap.setMyLocationEnabled(true); // error --------------------------
mMap.getUiSettings().setMyLocationButtonEnabled(true); -
mMap.getUiSettings().setZoomControlsEnabled(true);
}
//in my manifest
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.things.permission.MANAGE_GNSS_DRIVERS" />

Related

java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource

Please understand that the question may be a little dizzy because it's my first time asking a question. Also, please understand that grammar may be strange because I am not good at English and use a translator.
I'm a person who is making apps using java in Android studios.
There was a continuous error trying to use Bluetooth. There were so many errors that I could easily find a solution, but it didn't apply to me.
Error Log
Process: org.techtown.push.bluetoothtest2, PID: 10852
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.techtown.push.bluetoothtest2/org.techtown.push.bluetoothtest2.MainActivity}: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10158, packageName = org.techtown.push.bluetoothtest2, attributionTag = null, token = android.os.BinderProxy#f43a396, next = null }: AdapterService getBondedDevices
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10158, packageName = org.techtown.push.bluetoothtest2, attributionTag = null, token = android.os.BinderProxy#f43a396, next = null }: AdapterService getBondedDevices
at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.bluetooth.IBluetooth$Stub$Proxy.getBondedDevices(IBluetooth.java:3077)
at android.bluetooth.BluetoothAdapter.getBondedDevices(BluetoothAdapter.java:2491)
at org.techtown.push.bluetoothtest2.MainActivity.showPairedDevicesListDialog(MainActivity.java:300)
at org.techtown.push.bluetoothtest2.MainActivity.onCreate(MainActivity.java:80)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7839) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
I think this sentence in the middle is the cause of the error.
Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10158, packageName = org.techtown.push.bluetoothtest2, attributionTag = null, token = android.os.BinderProxy#f43a396, next = null }: AdapterService getBondedDevices
But I've already applied a solution to the problem. This is my Manifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.techtown.push.bluetoothtest2">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
<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/Theme.Bluetoothtest2">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I applied it because I saw that I needed "android.permission.BLUETOOTH_CONNECT permission." However, errors continue to occur.
Am I misunderstanding something? Or did I make a mistake in mainactivty.java?
For your information, I made it like this when I made a project.
minimun sdk : API 16 : Android 4.1 (Jelly Bean)
If there is no problem with the file you wrote down, please tell me to review the Java code again.
Thank you.
since Android 6.0 not every permission is granted just because its placed in manifest. you have to handle runtime permission flow with BLUETOOTH_CONNECT one (how to request in HERE)
The BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, and BLUETOOTH_SCAN permissions are runtime permissions. Therefore, you must explicitly request user approval in your app before you can look for Bluetooth devices, make a device discoverable to other devices, or communicate with already-paired Bluetooth devices.
You should declare BLUETOOTH_SCAN and permissions in the Manifest and in the Activity.java
For example:
AndroiManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed only if your app looks for Bluetooth devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"
tools:ignore="ProtectedPermissions" />
MainActivity.java
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_PRIVILEGED
};
private static String[] PERMISSIONS_LOCATION = {
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_PRIVILEGED
};
and
private void checkPermissions(){
int permission1 = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
int permission2 = ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN);
if (permission1 != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
this,
PERMISSIONS_STORAGE,
1
);
} else if (permission2 != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(
this,
PERMISSIONS_LOCATION,
1
);
}
}

Android 4.2.2 Unable to create directory

Create Directory error vers 4.2.2 Google Api
Download Music and Error
6.0 Work
A very small number of users can return this error. The directory does not exist or can not be read.
FATAL EXCEPTION: main java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/muzikcaddesi
at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:503)
at com.mp3player.searchonline.SongFragment$3$1.onClick(SongFragment.java:158)
at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
at android.widget.AbsListView$1.run(AbsListView.java:3423)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
06-24 10:35:54.133 4183-4196/com.muzikcaddesi.muzikcaddesi E/GAv4: Successfully bound to service but never got onServiceConnected callback
My permission control
if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_INTERNET);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_PHONE_STATE}, 1);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_INTERNET);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_NETWORK_STATE}, 3);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.INTERNET}, 4);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_SETTINGS}, 5);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WAKE_LOCK}, 6);
}else{
My manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="25" />
<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.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1.please check /mnt/sdard exists and can be writed;
2.please check /mnt/sdcard/muzikcaddesi if it already exists as a file;
3.please check your device's sdcard path is /mnt/sdcard.and do you use Environment.getExternalStorageDirectory().getPath()) to get sdcard path?
4.or you can use another methodsetDestinationInExternalFilesDir.

I need help for Google Map API

yet I have another problem with my android app
I developed a pretty basic application that contains a single Activity and displays google maps (I used google maps API). The compilation ends with no errors, I also generate the apk without any problems but when I run my application on different devices only displays a blank page with the Google sign below this page.
[![This the screenshot of my application][1]][1]
package com.example.amine.bea_mapapp;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">My API key is here</string>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amine.bea_mapapp">
<permission android:name="com.androidcom.example.amine.bea_mapapp.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.androidcom.example.amine.bea_mapapp.MAPS_RECEIVE"/>
<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.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.androidcom.example.amine.bea_mapapp.providers.gsf.permission.READ_GSFREVICES"/>
<uses-feature android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="My API key is here" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
First thing you need to check Google account in that device is logged in or not
Second thing check inbuilt map in your testing device is working fine or not. Because google map access some services from device existing map application and your google account.?
Seems problem with your Google API keys. What key are you using at
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="My API key is here" />
If still struggling with issue, generate a new Google Map API keys with a keystore generated from your machine and build apk with that new MAP API key. I am sure it will work in all devices then.

STATUS_NETWORK_ERROR_OPERATION_FAILED in Android

I am implementing the necessary code. But when I try to submit the score I am getting this error. I tried out the solutions provided in answers to different questions, but I couldn't solve my problem.
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupView();
beginUserInitiatedSignIn();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.play_button:
Games.Leaderboards.submitScoreImmediate(getApiClient(),
getString(R.string.leaderboard_winner),
numGuesses).setResultCallback(new myLeaderBoardSubmitScoreCallback());
numGuesses++;
break;
case R.id.bests:
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), getString(R.string.leaderboard_winner)), 2);
break;
}
}
Android Manifest Permisssions:
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
Based from the documentation, STATUS_NETWORK_ERROR_OPERATION_FAILED error means that a network error occurred while attempting to perform an operation that requires network access. There is a possibility that you are not signed in when this error occurs. Make sure to perform some sort of check, such as getGamesClient.isConnected() or isSignedIn().
Also, maybe you are submitting a score greater than the one you have configured on the console to be the min value for that leaderboard.

HttpUtils.httpConnection() refused

I have used this code to send an mms and all parameters are correct, but the connection is refused.. And the netWork is connected on mobile mms.
HttpUtils is a class from a library downloaded here : https://github.com/android/platform_packages_apps_mms
HttpUtils.httpConnection(getApplicationContext(), 4444L, MMSCenterUrl, bytesToSendFromPDU, HttpUtils.HTTP_POST_METHOD, !TextUtils.isEmpty(MMSProxy), MMSProxy, port);
06-29 19:51:26.208: I/Log MMSCenterUrl(13071): http: //mmsnrj
06-29 19:51:26.208: I/Log MMSProxy(13071): 10.143.156.5
06-29 19:51:26.208: I/Log MMSPort(13071): 8080
06-29 19:51:26.288: E/Mms:transaction(13071): Url: http: //mmsnrj
06-29 19:51:26.288: E/Mms:transaction(13071): Connection to http: //10.143.156.5:8080 refused
Manifiest file :
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_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.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
Crossing out usual suspects
Uses Internet permission in manifest file
Server is actually up.Please send a post request form the browser using Post master or any such tool
10.143.156.5 ip seems its an external system. Ensure that firewalls are not making your development life miserable. (Port forwarding or open the port on the routers)

Categories