While trying to implement SafetyNet, I've added this dependency:
implementation 'com.huawei.hms:safetydetect:6.3.0.301'
And also added the permission to AndroidManifest.xml:
<uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE"/>
But this somehow doesn't work as expected:
E/RootDetect: `isRoot` exception : Must have `com.huawei.permission.SECURITY_DIAGNOSE` permission.
Neither user `10200` nor current process has `com.huawei.permission.SECURITY_DIAGNOSE`.
Also below Apps & services > Permissions > View all permissions, it is not listed - all the others are being merged. Are there any further conditions or is the permission possibly being stripped out while merging? The AGP version is 7.1.2.
The strange thing is, that I still get the error message, when commenting out the dependency.
Huawei Safety Detect Kit doesn't require below permission "SECURITYDIAGNOSE", instead it requires only for "INTERNET" AND "ACCESSWIFI_STATE". Pls refer to below URL for sample code example and guide.
uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE
<uses-permission android:name="android.permission.INTERNET" />
<!-- Access WiFi State -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
https://developer.huawei.com/consumer/en/doc/development/Security-Examples/sample-code-0000001050157020
https://developer.huawei.com/consumer/en/doc/development/Security-Guides/dysintegritydevelopment-0000001050156331
Must have com.huawei.permission.SECURITY_DIAGNOSE permission.
This customized permission does not need to be added to the SafeDetect Kit. In addition, the customized permission is not displayed on the permission management page. Generally, the system-level permission is displayed on the permission management page.
String alg was undefined; here's a working version of the example source:
SafetyDetectClient mClient = SafetyDetect.getClient(this);
// TODO: Change the nonce generation to include your own,
// used once value, ideally from your remote server.
byte[] nonce = ("Sample" + System.currentTimeMillis()).getBytes();
SysIntegrityRequest sysintegrityrequest = new SysIntegrityRequest();
sysintegrityrequest.setAppId("3*******"); // TODO: set your appId.
sysintegrityrequest.setNonce(nonce);
sysintegrityrequest.setAlg("RS256"); // or "PS256"
Task<SysIntegrityResp> task = mClient.sysIntegrity(sysintegrityrequest);
task.addOnSuccessListener(response -> {
// Indicates that communication with the service was successful.
String jwsStr = response.getResult();
Log.d(LOG_TAG, "SysIntegrityResp: " + jwsStr);
}).addOnFailureListener(e -> {
// An error occurred during communication with the service.
if (e instanceof ApiException) {
// An error with the HMS API contains some additional details.
ApiException apiException = (ApiException) e;
// You can retrieve the status code using the apiException.getStatusCode() method.
Log.e(LOG_TAG, "Error: " + SafetyDetectStatusCodes.getStatusCodeString(
apiException.getStatusCode()) + ": " + apiException.getMessage()
);
} else {
// A different, unknown type of error occurred.
Log.e(LOG_TAG, "ERROR: " + e.getMessage());
}
});
Now I don't know how to get or validate the nonce or what to do with the jwsStr, but I get one SysIntegrityResp - but that's another question. The part of the documentation, which suggests to add the permission seems to be slightly misleading - and the error message in the log as well. Just found this Java server example source, which supports the understanding a lot. When filtering the log for hmssafetydetect, one can see what's happening.
I'm trying to implement Amazon IAP in a xamarin project following the documentation here.
So here's how my manifest looks like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="87" android:versionName="8.7" package="XXXXXXXXXXXX">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:icon="#mipmap/ic_launcher" android:label="XXXXXXXXXXXX">
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="XXXXXXXXXXXX" />
<receiver android:name="com.amazon.device.iap.ResponseReceiver" android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" >
<intent-filter>
<action android:name="com.amazon.inapp.purchasing.NOTIFY" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And here's my code which is in the Android Project of my solution:
public async Task<bool> MyMethod()
{
try
{
var iapService = AmazonIapV2Impl.Instance;
var tcs = new TaskCompletionSource<bool>();
var skus = new SkusInput { Skus = new List<string>() { "XXXXXXXXX" } };
var requestId = iapService.GetProductData(skus).RequestId;
GetProductDataResponseDelegator delegator = null;
delegator = new GetProductDataResponseDelegator(async response =>
{
await Task.Run(() =>
{
DoSomething();
tcs.SetResult(result);
});
});
iapService.AddGetProductDataResponseListener(delegator.responseDelegate);
await tcs.Task;
}
catch(Exception ex)
{
}
return true;
}
This doesn't throw exceptions but the method DoSomething(); is never called and the last line return true; is never reached. Also the line tcs.Task is stuck on WaitingActivation status. It's like the listener/reciever wasn't working. So my code endlessly wait for the answer.
Any idea how to fix this?
I'm using Xamarin Form version: 5.0.0
Running on Mac, through Visual Studio and debugging on a simulator or a real device (Xiaomi mi9)
Thanks
So first of all the code await Task.Run(() => wasn't necessary to make it work. Secondly, the problem was that my app wasn't submitted yet on the Amazon AppStore and so to test a non-submit app you need to download on your testing phone the app:Amazon App Tester.
In case you have issue to download the Amazon App Tester read this:
In the past, I've tried to download the Amazon App Tester but for some reason my phone didn't want it. I finally "bought" it (it's $0.00 anyway) from my computer on amazon website. Once bought, I was able to find the app in the tab "my app" in the Amazon AppStore on my phone.
Azure Active Directory
Google+ Auth
Xamarin Forms, PCL (NuGet 2.4.0.282)
Microsoft.Azure.Mobile.Client 4.0.0 & 4.0.2
After I successfully Login my phone does not return to my app. I have two test phones and one emulator, they display different info, after login.
Phone 1 (AAD Auth):
Phone 1 (Google Auth it greys out and just keeps "loading")
Phone 2 (AAD and Google Auth):
Emulator (AAD and Google Auth):
I have done everything I found here on Stack OverFlow, that makes sense and seems to be applicable to current versions of NuGets.
This person seems to be having a similar issue to me but with Google Log in
Azure not redirecting after loginenter link description here
I have tried integrating code into my project. And then I input my Azure info into Xamarin's sample: https://github.com/xamarin/xamarin-forms-samples/tree/master/WebServices/TodoAzureAuth
And I get the same results. I have tried both AAD and Google+ Auth. After login it just stays at the browser. So I feel like the client side code has to be correct. But I cant find any mess up on my Azure server code. I have tried this with projects that have a C# and Node.Js backend.(For one of my projects) My ALLOWED EXTERNAL REDIRECT URLS is ToDoList53172://easyauth.callback and in my AndroidManifest.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.xamarin.sample.TodoAzure">
<uses-sdk android:minSdkVersion="15" />
<application android:label="TodoAzure" android:icon="#drawable/icon">
<activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" android:launchMode="singleTop" android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="ToDoList53172" android:host="easyauth.callback" />
</intent-filter>
</activity>
</application>
</manifest>
OLD:
And I don't feel like I should post all the other code. It is all in the Xamarin sample project posted above. If people think I should I will.
NEW:
I am adding more code just to help people out. I did not want to overload, but better to have all the info in one place. So here is my MainActivity.cs Code
using System;
using System.Threading.Tasks;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Microsoft.WindowsAzure.MobileServices;
using Android.Webkit;
namespace TodoAzure.Droid
{
[Activity(Label = "TodoAzure.Droid",
Icon = "#drawable/icon",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
Theme = "#android:style/Theme.Holo.Light")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity, IAuthenticate
{
MobileServiceUser user;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
App.Init((IAuthenticate)this);
LoadApplication(new App());
}
public async Task<bool> AuthenticateAsync()
{
bool success = false;
try
{
if (user == null)
{
// The authentication provider could also be Facebook, Twitter, or Microsoft
user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(this, MobileServiceAuthenticationProvider.Google, Constants.URLScheme);
if (user != null)
{
CreateAndShowDialog(string.Format("You are now logged in - {0}", user.UserId), "Logged in!");
}
}
success = true;
}
catch (Exception ex)
{
CreateAndShowDialog(ex.Message, "Authentication failed");
}
return success;
}
public async Task<bool> LogoutAsync()
{
bool success = false;
try
{
if (user != null)
{
CookieManager.Instance.RemoveAllCookie();
await TodoItemManager.DefaultManager.CurrentClient.LogoutAsync();
CreateAndShowDialog(string.Format("You are now logged out - {0}", user.UserId), "Logged out!");
}
user = null;
success = true;
}
catch (Exception ex)
{
CreateAndShowDialog(ex.Message, "Logout failed");
}
return success;
}
void CreateAndShowDialog(string message, string title)
{
var builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.SetNeutralButton("OK", (sender, args) => { });
builder.Create().Show();
}
}
}
And Like I said above I have tried this with AAD as well. The code above is for Google.
Here is my Azure Auth setup
Here is the info I get after logging in with "https://todolistjbb.azurewebsites.net/.auth/login/aad" and then visiting
"https://todolistjbb.azurewebsites.net/.auth/me"
I feel like I have tried SO many things. I have recorded 66.68 hours working on just trying to get Authentication in my app.... please... someone tell me what I am doing wrong! I am losing it over here :'(
The way to solve this problem is do not start with a capitalized letter for your Url Scheme. It took me over 2 weeks to figure it out. I don't think this sis written anywhere, but I am sure it is.
So yeah to fix this i switched "ToDoList53172" to "todolist53172"
That's it... Oy vey!
According to your description, I assumed that you are using the Server-managed authentication provided by Azure App Service authentication/authorization. Since you are using the Microsoft.Azure.Mobile.Client >= 4.0.0, for your mobile client, you would leverage the following code snippet for logging via the server-flow:
var user = await client.LoginAsync(this, provider, "{url_scheme_of_your_app}");
Details you could follow Add authentication to the app. Moreover, you need to Add your app to the Allowed External Redirect URLs.
Based on the error message from your phone 2:
todolistjbbservice://easyauth.callback/#authorization_code=xxxxx
It seems that you did not configured the Authorized Redirect URI correctly. For the Azure Active Directory provider, you could follow here for registering your Web App / API or Native application. For the Google provider, you could follow here.
After correctly configured your preferred identity provider(s), you need to add your app to the Allowed External Redirect URLs:
Log into Azure Portal, choose your App Service
Click the Authentication / Authorization,
enter ToDoList53172://easyauth.callback in the Allowed External Redirect URLs, and save your changes.
I have created a Flash CS6 AIR for Android application with the Freshplanet ANE for push notifications. Everything seems to be working, but I am still not receiving the notifications on my device.
Here is my Flash CS6 code:
import com.freshplanet.nativeExtensions.PushNotification;
import com.freshplanet.nativeExtensions.PushNotificationEvent;
txtMsg.text = 'starting..';
var push:PushNotification = PushNotification.getInstance();
if (push.isPushNotificationSupported) {
push.registerForPushNotification("XXXXXXXXXXXXX"); //Google project ID
}
push.addEventListener(PushNotificationEvent.PERMISSION_GIVEN_WITH_TOKEN_EVENT, onRegistered);
push.addEventListener(PushNotificationEvent.PERMISSION_REFUSED_EVENT, onRefused);
function onRegistered(event:PushNotificationEvent):void
{
txtMsg.appendText("Registered with registration id:" + event.token);
}
function onRefused(event:PushNotificationEvent):void
{
txtMsg.appendText("Refused:" + event.errorMessage);
}
This code seems to work, because when i launch my App on my device, my txtMsg field displays the event.token. A long string containing what Im guessing to be the unique device id.
My Android manifest looks like this:
`
<android>
<manifestAdditions>
<![CDATA[<manifest>
<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_WIFI_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="air.it.test.PushTest2.permission.C2D_MESSAGE" />
<permission android:name="air.it.test.PushTest2.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<application>
<activity android:name="air.it.test.PushTest2"></activity>
<receiver android:name="com.freshplanet.nativeExtensions.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="air.it.test.PushTest2" />
<intent-filter>
</intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="air.it.test.PushTest2" />
</intent-filter>
</receiver>
<service android:name="com.freshplanet.nativeExtensions.LocalNotificationService"/>
<receiver android:name="com.freshplanet.nativeExtensions.LocalBroadcastReceiver" android:process=":remote"></receiver>
</application>
</manifest>]]>
</manifestAdditions>
</android>
<extensions>
<extensionID>com.freshplanet.AirPushNotification</extensionID>
</extensions>
`
This is my VB.NET server application which sends the message to the device with the token received above.
Dim regId As String = "XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXX" device token id
Dim MessageText As String = "Hope this works"
Dim applicationID As String = "APP ID" 'received from Google API console as the Key for server applications
Dim result As String = ""
Dim SENDER_ID As String = "XXXXXXXXXXXXX" 'same ID used in my actionscript file above - Google project ID
Dim httpWebRequest As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
httpWebRequest.ContentType = "application/json"
httpWebRequest.Method = "POST"
httpWebRequest.Headers.Add(String.Format("Authorization: key={0}", applicationID))
httpWebRequest.Headers.Add(String.Format("Sender: key={0}", SENDER_ID))
Dim streamWriter As StreamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
Dim json As String = "{""registration_ids"": [""" & regId & """], ""data"": {""message"": """ & MessageText & """}}"
Response.Write(json)
streamWriter.Write(json)
streamWriter.Flush()
streamWriter.Close()
Dim httpResponse As WebResponse = httpWebRequest.GetResponse()
Dim streamReader As StreamReader = New StreamReader(httpResponse.GetResponseStream())
result = streamReader.ReadToEnd()
Response.Write(result)
When i run this function, it get a success message. So everything seems to work correctly, but my device doesn't receive anything. What am i doing wrong? Thanks
Fresh Planet have many branches, try this which is more recent:
https://github.com/freshplanet/ANE-Push-Notification/tree/feature/famepop-withOptions
And you need change the JASON to send these values:
contentTitle <---- this is the title
contentText <---- this is the message
tickerText <---- this is showed in the task bar
This?
push.addEventListener(PushNotificationEvent.COMING_FROM_NOTIFICATION_EVENT, onPushMessage);
I received the above exception when trying to implement Sample Sync Adapter application. I have seen numerous posts related to this issue but no satisfactory response.
So I will jot down my solution here in case anyone else gets into the same issue.
Some other useful tips to debug problems like this.
First enable verbose logging for some tags:
$ adb shell setprop log.tag.AccountManagerService VERBOSE
$ adb shell setprop log.tag.Accounts VERBOSE
$ adb shell setprop log.tag.Account VERBOSE
$ adb shell setprop log.tag.PackageManager VERBOSE
You'll see logging like this:
V/AccountManagerService: initiating bind to authenticator type com.example.account
V/Accounts: there is no service connection for com.example.account
V/Accounts: there is no authenticator for com.example.account, bailing out
D/AccountManagerService: bind attempt failed for Session: expectLaunch true, connected false, stats (0/0/0), lifetime 0.002, addAccount, accountType com.example.account, requiredFeatures null
Which means that there is no authenticator registered for this account type. To see which authenticators are registered watch the log when installing the package:
D/PackageManager: encountered new type: ServiceInfo: AuthenticatorDescription {type=com.example.account}, ComponentInfo{com.example/com.example.android.AuthenticatorService}, uid 10028
D/PackageManager: notifyListener: AuthenticatorDescription {type=com.example.account} is added
I had the problem that the authenticator xml descriptor referred to a string resource which didn't get resolved properly during the installation:
android:accountType="#string/account_type"
The logs showed
encountered new type: ServiceInfo: AuthenticatorDescription {type=#2131231194}, ...
Replacing it with a normal string (not resource) solved the problem. This seems to be Android 2.1 specific.
android:accountType="com.example.account"
First, check the condition explained on this post:
[...] If you see an error from the AccountManagerService of the form caller uid XXXX is different than the authenticator's uid, it might be a bit misleading. The ‘authenticator’ in that message is not your authenticator class, it’s what Android understands to be the registered authenticator for the account’s type. The check that happens within the AccountManagerService looks like this:
private void checkCallingUidAgainstAuthenticator(Account account) {
final int uid = Binder.getCallingUid();
if (account == null || !hasAuthenticatorUid(account.type, uid)) {
String msg = "caller uid " + uid + " is different than the authenticator's uid";
Log.w(TAG, msg);
throw new SecurityException(msg);
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "caller uid " + uid + " is the same as the authenticator's uid");
}
}
Note that hasAuthenticatorUid() takes the account.type. This is where I’d screwed up. I was creating my Account with a type specified by a constant:
class LoginTask {
Account account = new Account(userId, AuthenticatorService.ACCOUNT_TYPE);
...
}
class AuthenticatorService extends Service {
public static final String ACCOUNT_TYPE = "com.joelapenna.foursquared";
...
}
but this constant did not match the XML definition for my authenticator:
<account-authenticator xmlns:android="/web/20150729061818/http://schemas.android.com/apk/res/android"
android:accountType="com.joelapenna.foursquared.account" ... />
Second, if you are like me and want to embed the sample into your existing app for testing then, make sure you use Constants class that is part of this example and not under android.provider.SyncStateContract package. Because both classes use the same attribute name ACCOUNT_TYPE that is used when creating Account object.
In my case the problem was very simply a mismatch in accountType declared in res/xml/authenticator.xml as android:accountType="com.foo" but referenced incorrectly as "foo.com" in creating the Account:
Account newAccount = new Account("dummyaccount", "foo.com");
Doh!
There are few parts to implement custom account...
To invoke AccountManager in your Activity, something like that you already implemented...
Account account = new Account(username, ACCESS_TYPE);
AccountManager am = AccountManager.get(this);
Bundle userdata = new Bundle();
userdata.putString("SERVER", "extra");
if (am.addAccountExplicitly(account, password, userdata)) {
Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, username);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCESS_TYPE);
setAccountAuthenticatorResult(result);
}
In res/xml/authenticator.xml you have to define your AccountAuthenticator data (responsible for your Authenticator UID). ACCESS_TYPE have to be the same string as your defined accountType in this xml!
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.buecherkiste"
android:icon="#drawable/buecher"
android:label="#string/app_name"
android:smallIcon="#drawable/buecher" >
</account-authenticator>
Finally you have to define your service your Manifest. Please do not forget the relevant permissions for manage your accounts (AUTHENTICATE_ACCOUNTS / USE_CREDENTIALS / GET_ACCOUNTS / MANAGE_ACCOUNTS)
<service android:name=".AuthenticationService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
My error was assuming the AccountManager getAccounts() method returned accounts only associated with my application context. I changed from
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccounts();
to
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
The same error will appear if you put incorrect values in your intent-filters in your manifest.
I went through the android-dev tutorial on sync-adapters and ended up setting a bogus value for the "intent-filter/action android:name" as well as "meta-data/android:name" for syncadapter/accountauthenticator. This mistake caused the same errors to appear in the logs.
For the record, the correct values are: {android.content.SyncAdapter, android.accounts.AccountAuthenticator}
Make sure that your service XML is pointing to the correct location.
For instance if you're module name is
com.example.module.auth
you're service android:name should be
<service android:name=".module.auth.name-of-authenticator-service-class"...
in AndriodManifest.xml
First off, take another look at Jan Berkel's excellent debugging advice.
Finally, another thing to check is that your content provider and the authentication, and sync services are declared as children of the application tag.
<application
...>
<activity
...(Activity)...
</activity>
<provider
...(CP service declaration)/>
<service
...(Authentication service declaration)...
</service>
<service
...(Sync service declaration)...
</service>
</application>
For me it was a very silly mistake and was very hard to find.
In authenticator.xml I wrote
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.myapp"
android:icon="#drawable/ic_launcher"
android:smallIcon="#drawable/ic_launcher"
android:label="#string/app_name"
/>
instead of
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.myapp"
android:icon="#drawable/ic_launcher"
android:smallIcon="#drawable/ic_launcher"
android:label="#string/app_name"
/>
which was causing this error. Hope this helps someone!
In my case it was permissions in manifest file
i had
<uses-permission android:name="ANDROID.PERMISSION.GET_ACCOUNTS"/>
it was all caps, when i changed it to
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
problem was gone
Also,
Check to see if you are treating the AccountType too much like a plain-old-String.
I have most of my code packaged under com.mycompany.android
I have been using the following AccountType with success: com.mycompany.android.ACCOUNT.
Now I have a desire to use multiple accounts, and when I try the approach of appending ".subType" on the end of my account, it fails with the
caller uid xxxxx is different than the authenticator's uid
However, if I use "_subType" ( underscore instead of dot ), it works fine.
My guess is that somewhere under the hood Android is trying to treat com.mycompany.android.ACCOUNT as a legal package name, which it most certainly is not.
So, again:
BAD com.mycompany.android.ACCOUNT.subType
GOOD com.mycompany.android.ACCOUNT_subType
If you are getting this error, and all the above solutions are not working for you. Also, you assume that you have followed all the procedure. There may be a chance that the Authentication Service is developed by some other developer, which you want to make use of to Add Accounts.
What you can try is try signing your application with a release keystore. Now you run the application. I suppose this should work for you.
Here is another one possible solution.
I had this error when my user was registered in my app with the same e-mail as his android google account.
So, when I tried to accountManager.getAccounts() and search for this e-mail I found an account with the same e-mail BUT with another account type. So, when trying to use this (google.com) account I get this error.
So, the right way to find an account is:
public Account findAccount(String accountName) {
for (Account account : accountManager.getAccounts())
if (TextUtils.equals(account.name, accountName) && TextUtils.equals(account.type, "myservice.com"))
return account;
return null;
}
Also make sure your AccountAuthenticatorService has the prover intent filters ;
ie.
<service android:name=".service.AccountAuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
If you get this exception at Samsung devices be sure that you are not using safe mode.
If same apps are from different store ,for example amazon app store and google play store , eventually security exception gonna be thrown as the signature of the apps would be different in this case .If u had planned to use same authenticator for the purpose of single sign in , either of the app would crash. i had encountered this trouble once. Especially amazon app store would sign its apps with its own signature for the purpose of security.
Note: If there is no typo error or other answers mentioned here , please check for the signature of the apps in case of single sign in.
For those who still expierienced issue: https://stackoverflow.com/a/37102317/4171098
In my case I accidently defined AuthenticatorService in the Manifest
outside the <application> tags. Moving the declaration inside
<application> fixed the issue. Hope will help someone.