Android Bluetooth_admin permission error - java

Regarding Android bluetooth discovery.
Getting this error from manifest permission error. However, the only errors that I found posted, was that they forgot to put the permission outside the application. This is however not the case here.
The program is tested on a Galaxy S2 running Jelly Bean 4.1.
The error is as follows:
03-19 13:08:03.933: W/dalvikvm(12616): threadid=1: thread exiting with uncaught exception (group=0x413082a0)
03-19 13:08:03.938: E/AndroidRuntime(12616): FATAL EXCEPTION: main
03-19 13:08:03.938: E/AndroidRuntime(12616): java.lang.SecurityException: Need BLUETOOTH_ADMIN permission: Neither user 10004 nor current process has android.permission.BLUETOOTH_ADMIN.
Basically the manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.motioncontrol"
android:versionCode="1"
android:versionName="1.0" >
<user-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:debuggable="true"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.motioncontrol.Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AccelerometerDat"
android:label="#string/accelerator_title" />
<activity
android:name=".GyroscopeData" />
<activity
android:name=".Gravitydat" />
<activity
android:name=".Linearacc" />
<activity
android:name=".Bluetooth" />
<activity
android:name=".CheckBluetooth" />
<activity
android:name=".About"
android:label="#string/about_title"
android:theme="#android:style/Theme.Dialog" />
</application>
</manifest>
And the class where the error occurs:
private void doDiscovery() {
if (D) Log.d(TAG, "doDiscovery()");
// Indicate scanning in the title
setProgressBarIndeterminateVisibility(true);
setTitle(R.string.scanning);
Log.d(TAG, "indicates scanning");
// Turn on sub-title for new devices
findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);
Log.d(TAG, "Set up sub-title for new devices");
// If we're already discovering, stop it
if (mBtAdapter.isDiscovering()) {
mBtAdapter.cancelDiscovery();
Log.i(TAG, "Already running discovering, stop it!");
}
// Request discover from BluetoothAdapter
mBtAdapter.startDiscovery();
Log.d(TAG, "Request discover form BluetoothAdapter");
}
Hope for an answer, what is going wrong :).
Thanks!

Change
<user-permission android:name="android.permission.BLUETOOTH_ADMIN" />
to
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<user-permission> is used to regulate the access to the current component by other application. You should try <uses-permission> to get the privilege.

Related

Flurry integration Android throwing errors

I'm trying to integrate flurry into my android app. I'm using the recommended setting and have repositories{jcenter()} and
// Required for Flurry Analytics integration
compile 'com.flurry.android:analytics:8.2.0#aar'
// Optional - If you want to use the Ads SDK
compile 'com.flurry.android:ads:8.2.0#aar'
in the gradle as the docs suggest. I keep getting errors in the that Application is not resolved. The docs really blow and I'm not 100% sure what going on. I've never integrated flurry before can someone please help! I put the manifest and the class i'm using below. I know it doesn't have a key I'm still working on removing errors. I'm dumping the that class in the main file for simplicity for now.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tempconversion.october.com.myapplication">
<!-- Required permissions - Internet access -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Highly Recommended permission - External memory pre-caching -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Optional permission - Location based ad targeting -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
android:roundIcon="#mipmap/ic_launcher_round"
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>
</manifest>
class in main file
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
new FlurryAgent.Builder()
.withLogEnabled(true)
.withCaptureUncaughtExceptions(true)
.withContinueSessionMillis(10)
.withLogLevel(VERBOSE)
.build(this, FLURRY_API_KEY);
}
}
Declare the application name in manifest.xml file.
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
android:roundIcon="#mipmap/ic_launcher_round"
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>

Android Studio: Application crashes at start

my application crashes at start and I have no idea why. I'm testing it on a real device (Samsung Galaxy S3 GT-I9300). Here is the exception:
EDIT:
So, that's what I've added to onCreate():
walking.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
travel_mode = "walking";
walking.setImageResource(R.drawable.walking_sel);
biking.setImageResource(R.drawable.regular_biking);
driving.setImageResource(R.drawable.car_icon);
transit.setImageResource(R.drawable.transit_icon);
}
});
biking.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
travel_mode = "biking";
walking.setImageResource(R.drawable.walking);
biking.setImageResource(R.drawable.regular_biking_sel);
driving.setImageResource(R.drawable.car_icon);
transit.setImageResource(R.drawable.transit_icon);
}
});
Before I've added this piece of code, everything worked correctly.
And here is AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lukssoftware.kaart" >
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="lukssoftware.kaart.kaart_welcome"
android:screenOrientation="portrait"
android:label="kaart" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Any ideas?
Thanks.
Please post more code and there is nothing to do with manifest here post layout xml and activity code where you have defined walking and biking findViews().
Just check it out that you have defined findViewsById of both walking and biking before you are calling setOnClickListener method.
Does your application still compile successfully after deleting the two modules?
If it doesn't compile, look for the lines in your classes or xml files which have yellow or red exclamation marks. That should alert you to where the problem is coming from.
You should also take a good look at line 64 in your *welcome.java class.

The app works fine on AVD, but not on real device

I really have very big problem with my project. When my phone is connected to the computer via USB cable, everything works fine, but when the phone is disconnected the app doesn't work as I expected. So, I have already tried with android.os.Debug.waitForDebugger(), I removed the all #SuppressLint("NewApi"), also USB debugger is activated on my phone, but I think the problem can be in the Manifest file. Can someone tell me, what can be done in this case?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/fritz_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:windowSoftInputMode="adjustPan"
android:name="com.example.androproject.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/ThemeWithCorners"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.androproject.RegisterDnsAndUser"
android:screenOrientation="portrait"
android:theme="#style/ThemeWithCorners"
android:configChanges="keyboardHidden|orientation"/>
<activity
android:name="com.example.androproject.MenuApp"
android:screenOrientation="portrait"
android:theme="#style/ThemeWithCorners"
android:configChanges="keyboardHidden|orientation"/>
</application>
</manifest>
I am using the following, handler code. When I put 40000 ms, the app works, but when I put 60000 ms, my application doesn't work if the cable is disconnected.
handler.postDelayed(myRunnable = new Runnable(){
#Override
public void run() {
if(btnToggle.isChecked()){
btnToggle.setChecked(false);
btnToggleTimer.setChecked(false);
}else{
btnToggle.setChecked(true);
btnToggleTimer.setChecked(false);
}
}
}, min*60000);
Most likely you have enabled the "Stay awake"-mode in the Developer options in the settings menu. When you disconnect the phone from the charger it will go into sleep mode after a few seconds.
The solution is to either use a partial wake-lock using the PowerManager or (in the above case) use a PendingIntent and the AlarmManager to trigger a event at a later time.

Google Play Services - Google login yields a network error

I am trying to integrate Google Play Services into my application in order to enable achievements. Upon application launch, a login attempt is being made which results in one of the following errors:
There was a problem communicating with Google servers.
Failed to log in. Please check your network connection and try again later.
A̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶ ̶c̶r̶a̶s̶h̶e̶s̶
The application is incorrectly configured. Check that the package name and signing certificate match the cliend ID created in Developer console. Also, if the application is not yer published, check that the account you are trying to sign in with is listed as a tester account. See logs for more information.
Logcat displays absolutely no data related to this problem so I don't even have a clue what could be wrong. The app is authenticated correctly, with the correct SHA1 certificate fingerprint and app id copied to manifest. Does anyone have any could what this could be?
Thanks.
EDIT: Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.*****.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.app.Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.app.GameAct"
android:label="#string/title_activity_game"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I resolved the issue I had by deleting Google+ data related to my previous game login and logging in again. I do not know what caused this error in the first place but it may be due to wrong settings in my Developer Console. I did change some things, like re-authenticated the app but the changes took effect only after deleting old data.

Android multiple instances of Activity

I'm having a problem where multiple instances of an activity are present in the backstack.
e.g.
Stack: A > B > C
Press home and use some other apps then relaunch my app
Stack: A > B > C > A
I would expect my app to resume with activity C, which in most cases it does, but occasionally it resumes with activity A and then when i press back it goes to activity C.
I know this problem is not caused by android killing my app as if this was the case it would resume with activity A as the root.
I have tried altering the launchMode attribute to singleTask and singleInstance but this results in activity A being resumed as the root, which is not the behaviour that i want, i want it to go back to the previously viewed activity with the backstack intact (I understand this is not always possible if the OS kills the app, which is fine).
I dont believe setting the launchMode attribute to singleTop would be useful either as this would prevent A > A situations but not A > B > A or A > B > C > A etc
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=""
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"
>
<application android:label="#string/app_name" android:debuggable="false"
android:name=""
android:icon="#drawable/icon" android:theme="#style/CustomTheme"
android:targetSdkVersion="8" android:minSdkVersion="4">
<activity android:name=".activity.A"
android:windowSoftInputMode="stateUnchanged|adjustPan"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.B"
android:screenOrientation="portrait"/>
<activity android:name=".activity.C"
android:screenOrientation="portrait" />
<activity android:name=".activity.D"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
<activity android:name=".activity.E"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
<service android:name=".service.S" />
<uses-library android:name="com.google.android.maps" />
</application>
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="8"
/>
<supports-screens
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Any advice would be greatly appreciated
David
The behavior you're looking for is what singleTask was meant for.
The problem, then, is why resuming your app pops back to the root. If it's just due to the usual way the system works (e.g., 30-minute timeout), and you really want to prevent that, you could use android:alwaysRetainTaskState="true".

Categories

Resources