Configuring the google account programmatically in Android - java

i need some help, i was trying configuring the google account behind the android, the main idea is don't use the wizard to configure the google account, i need do this by code, i was searching, but don't successfully, the only way I was trying to do was the following, but I believe that this is merely a way to make my current application tivese access the account I'm trying to use, but still without success
#Override
public void onClick(View v) {
try{
AccountManager mgr = AccountManager.get(this);
Account acc = new Account("sexo#gmail.com", "com.google");
if(mgr.addAccountExplicitly(acc, "pass", new Bundle())) {
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_LONG);
}
}catch(Exception e){
Log.d("test", e.getMessage());
Log.d("test", e.toString());
e.getStackTrace();
e.printStackTrace();
}
And this is my manifest used
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actteste"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permaission.INTERACT_ACROSS_USERS_FULL"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:installLocation="internalOnly">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.company.demo.account.AuthenticatorService" android:exported="false">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator"/>
</service>
</application>
</manifest>
I tried to create a service and also reference in my manifest
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.company.demo.account.DEMOACCOUNT"
android:icon="#drawable/ic_launcher"
android:smallIcon="#drawable/ic_launcher"
android:label="qualquer"/>

You cannot use the account manager to setup a new account on the Google server. It can only be used for login.
The Setup application in Android also has no API available for setting up a new account. The only real way would be to reverse engineer their application code and try to inject values. It not smart and here is why:
All of this is designed this way for customer safety and Google protection. When doing this in an automated way, the customer is not agreeing to the Terms and Conditions as well as creating an account with dangerous access to user information on the device or from the device itself.
If this is 100% required, I suggest that you have the device communicate to a server you own which handles the negotiations with Google and alerts the user accordingly. Its not what you may want to hear, but this is not an advisable route.

Related

<uses permission> in android studio is not working / application is not asking for permission

I am trying to make an app which starts by asking permission and accesses the hotspot of any device and any android version with which the very first problem which is bothering me is that why is not working, i have tried it on two devices and both of the attempts were unsuccessful.Please can anyone help me out to point my mistake. I checked similar questions related to it and have tried correcting it too but still not working..
here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.akshay.turnonhotspot2">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<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">
<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>
It is changed since Android API 23.
You also have to ask permissions at Runtime.
Check this document
Permissions are asked when when you need user personal data such as contacts, storage(photo, video, file) and etc..
You don't need to ask permission for android.permission.INTERNET, android.permission.ACCESS_NETWORK_STATE, android.permission.ACCESS_WIFI_STATE, android.permission.CHANGE_WIFI_STATE

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.

What's wrong with google map API v2?

This issue is common BUT I didn't find a solution on google, or stackoverflow (4days of research...)
Here is the thing :
I need to display a full screen google map, which i ve already done several times in other application i've developped.
BUT here i can't get it to work for an unknow reason !
The warning and the error i get when i open the SherlockFragmentActivity which contains the map :
The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Here i'll explain how i did things in detail and post some code :
LIBRARY IMPORT :
Last version of Google play services imported in eclipse as library (checked)
In the project the google play services are imported as library in properties (like ABS)
MANIFEST :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pck name"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.company.pckgname.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<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" />
<!-- LOCATION -->
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name="app variable name"
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme.Styleapp" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key" />
<activity
android:name=".ActivityLauncher"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.Sherlock.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... activities...
</application>
</manifest>
MAP LAYOUT :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.company.pckgname.TransparentSupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
ACTIVITY :
public class ActivityGoogleMap extends SherlockFragmentActivity implements OnInfoWindowClickListener {
GoogleMap _googleMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// ABS
ActionBar bar = getSupportActionBar();
bar.setTitle(R.string.tle_map);
bar.setDisplayHomeAsUpEnabled(true);
// MAP
_googleMap = ((TransparentSupportMapFragment) getSupportFragmentManager().findFragmentById((R.id.map))).getMap();
//the map should still display at this point
}
}
And so that's it, the main code is here
The map was working up until now, i didn't do nything with the code map related...
I tried to regenerate a debug key on the google console, change the permissions .. etc i am out of idea !!!!
After changing the API key in AndroidManifest.xml you must clear application data.
To clear application data do one of the following:
Go to Settings > Application Manager > Select Your Application > Clear Data
Uninstall the application before re-installing it.
<uses-feature android:glEsVersion="131072" android:required="true" />
Put this under your permissions in your manifest.

google map does not show up

I'm trying to display the google map for an android project. I followed all the steps without any problems, but when i launch my application, the map simply doesn't show up, i just have a white screen.
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MyKeyXXXXXXX" />
<activity
android:name="com.map.HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.map.MapActivity"
android:label="#string/title_activity_map" >
</activity>
</application>
</manifest>
Does anyone see something wrong ?
thanks in advance
Here are the steps you should follow:
Grab the Google Play services SDK (It's where the Maps API is)
Get the API key
Set the key in the Application Manifest
Last but not least, don't forget that Google Maps will only show if your app is signed with the key you provided to get the Maps key.
For example, if you've used a production certificate and you're testing the app with the debug key, you won't be able to see the maps.
I had this problem too. Your API key is not the giant series of two characters. On the Google Maps API console, after you have created your project and enabled Google Maps, you need to go to the API Access page, and click on "Create a new Android Key" if you don't have one already.
Your API Key that you use in your app is the ~40 character string that appears on the new key. Paste that into the Manifest and it should work.

Categories

Resources