AWS Cognito Integration - android

I am working to integrate the Login Screen of an application I am working to create with AWS Cognito and have been following the step by step instructions to connect with the server.
STEP 5 OF 7
Copy the Mobile Hub Helper and Custom Code
Copy the src/main/java/com/amazonaws folder from the code you downloaded into the java/com folder of your Android Studio project.
This folder contains a set of helper classes that have been custom generated for you. These were generated based on your project configuration and on the AWS cloud resources and identifiers that were created for you when you configured the project. These classes simplify the use of all the SDKs that are required to support your project.
It also contains the source code for the AWSMobileClient which is a singleton component which bootstraps the app and creates an identity manager to establish the user identity with Amazon Cognito. If your project uses the Mobile Hub NoSQL feature the AmazonAws folder will also contain model classes that simplify your access to the DynamoDB tables you configured.
I believe I am running into problems with the last half of this bit as I am unsure what a singleton component is or how to insert it into the code. I have created it as a Java class and included the included code
package com.your.app;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import com.amazonaws.mobile.AWSMobileClient;
/**
* Application class responsible for initializing singletons and other common components.
*/
public class Application extends MultiDexApplication {
private final static String LOG_TAG = Application.class.getSimpleName();
#Override
public void onCreate() {
Log.d(LOG_TAG, "Application.onCreate - Initializing application...");
super.onCreate();
initializeApplication();
Log.d(LOG_TAG, "Application.onCreate - Application initialized OK");
}
private void initializeApplication() {
// Initialize the AWS Mobile Client
AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());
// ... Put any application-specific initialization logic here ...
}
}
however I get a red line in the manifest because it is not connected to an XML file, however the instructions never say to add an XML or to attach it to an XML file so im not sure how to connect these features. I imagine that the Application class should be populated following startup i.e. App opens to the login screen and it somehow initiates the communication with the server to transmit the strings which are typed into the text fields.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jason.mvp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity" 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=".Application"/>
<activity android:name=".MainActivity" />
<activity android:name=".RegisterActivity" android:theme="#style/NoActionBar"
android:parentActivityName="com.example.jason.mvp.LoginActivity" >
</activity>
</application>
</manifest>
can anyone help me!? Thank you!

Jessy,
It looks like you didn't do step 7 yet or did it wrong? Rather than have .application as an activity you should instead add it directly under application:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.example.jason.mvp.Application">
Have you started the integration steps for "User Sign-In" yet? You have to walk through those steps as well. One way to display the login view is to use a splash activity as is discussed in step 3 of the user sign-in integration steps.
Kevin

Related

Defining your own permissions in android

I am trying make my own permission for android application.
For this my android manifest file looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.happybirthday" >
<permission
android:name="com.example.hp.happybirthday.PERM"
android:description="#string/pdesc"
android:label="#string/CAREFUL"
/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:permission="com.example.hp.happybirthday.PERM">
<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>
</application>
</manifest>
The problem that I am facing is that I want to have my own permission associated with this application and hence i have added the following line as shown above under the application tag, so that only those activities have access to this app which possess my defined permission.
android:permission="com.example.hp.happybirthday.PERM"
But the problem is that when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed.
But when I remove the above mentioned line, it works, but then any activity will have access to this app which I do not want.
when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed
That is because the home screen is an app, and the home screen does not hold your custom permission. Hence, the home screen cannot start your launcher activity.
then any activity will have access to this app which I do not want
First, custom permissions do not work all that well.
Second, permissions are usually applied at a finer granularity than "this app". You only secure those components that need the security, and you leave public other components, like the launcher activity.
It looks like you've defined the permission, and set it to be required... but you haven't actually granted it to your own app. Add a uses-permission tag

Datastore Entities not showing

https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial/
Almost halfway down this webpage at heading "Test Client and Backend Communication", at Step 8: when i visit localhost:8888/_ah/admin/
i am not seeing any entity in the dropdown (this is my third try to this tutorial. At first two tries i would only see one entity 'MessageData' out of three.) I should see three entities, esp. CheckIn.
I am stumped. Plus, i am in the learning phase. What must i do in order to create an entity in the datastore?
Thank you in advance.
Here is the code for the MainActivity:
https://github.com/GoogleCloudPlatform/solutions-mobile-shopping-assistant-backend-java/blob/master/MobileAssistant-Tutorial/Phase1_Snippets/MainActivity.01.java
You have first to generate the Cloud EndPoint Library.
Then, you have to check if you have this lign on AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
The first classe you run when you launch an android app is define here:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<!-- Notre activité SplashScreen -->
<activity android:label="#string/app_name" android:name="com.example.test.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Hope that help you !

Can't get Parse.com framework to work

I've been trying to put data to Parse Cloud for days and I can't really figure out why it is not working.
I included both libs (Parse and bolts-android) and followed several tutorials on the web. My code is as following:
package com.dannyvdz.testapp2;
import android.app.Activity;
import android.os.Bundle;
import com.parse.Parse;
import com.parse.ParseObject;
public class ParseApplication extends Activity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.parseapplication);
Parse.initialize(this, "************", "************");
// Test creation of object
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dannyvdz.testapp2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".ParseApplication"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The app compiles and runs without errors but no code is being sent to Parse.com. I tried both running the app from Android studio and running it after building it installing it using adb. I can't seem to figure out what I am doing wrong. Any help would be greatly appreciated since I think my hairs starting to go grey because of this...
are you sure you have internet connection on the (emulator or your device) ??
can you try:
testObject.saveEventually();
change it with:
testObject.saveInBackground();
I'm not sure as to why but the application works on my tablet and the android emulator so the problem is my phone. I guess I should factory reset my phone (or wait for my new nexus 6 and work with my tablet in the meantime).
Thanks for all the help!
Update: Several days later I checked Logcat again and I found some messages which make me think of my android adblocker (adfree). I disabled adfree and it started working again. At least I figured it out!

Android: Google Maps not displaying

I'm trying to get a google map to display. I can see the background (light gray background, small tiles, Google logo in the lower left), so I know that I'm close. However, there is no actual map displayed. In the LogCat, I see this message repeating over and over:
05-14 13:28:17.926: W/System.err(27458): at
android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
I'm using Google maps api 2 with a tethered phone for testing that is running 2.3.4.
Anyone know what might be causing this? Thanks!
package com.example.maptest;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MyMapActivity extends MapActivity {
private MapView mapView;
private MapController mapController;
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView)findViewById(R.id.map_view);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptest"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="com.example.maptest.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.example.maptest.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"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:required="true" android:name="com.google.android.maps" />
<activity
android:name="com.example.maptest.MyMapActivity"
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=".MainActivity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
This problem is usually related to the map API key used to sign manifest. Take a look at this post and this one which describe the same error you are experiencing. In both cases it is because the API key they used was created with the wrong keystore. You need to make sure you use your debug keystore when you create an API key in the Google API console if you are going to be testing from eclipse.
Basically you are mixing deprecated Android API v1 with the new API v2.
The easiest way to migrate is to remove all v1 related code and start from scratch, following this link: https://developers.google.com/maps/documentation/android/start
go to developper console enable maps api for your device and then copy your key and paste in values->google_maps_api.xml . It works
Use Android key(auto created by google service) if on android devices
After days of struggle, I found the issue.
In my manifest I had the key value stored in an xml file and it didn't work.
Now i have
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzxxxxxxxxxxxxxxxxxxxxxxxkey" /> and it works.
Just removed the xml file...
Hope it helps!
If you have several packages in your app beware when you create the API key you must use the package name that included in top of the android mainfest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
**package="com.xxx.xxx"**
android:versionCode="1"
android:versionName="1.0" >
well actually I had lived this problem and it makes me crazy. after I found the solution. very simple:
1- in your project, google_maps_api.xml just check the web link is for your package name, if your package name exist and correct. go to page and get the key
To get one, follow this link, follow the directions and press "Create"
at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=...
2- just create new gooogle maps activity project get the SHA-1 code.
dont forget SHA-1 code is same in your other project but web link is uniqu for each your program
I had the same problem. The problem was in my manifest file. Check if the google maps key you have stored IN STRING.xml and google maps key in google_maps_api.xml does not have same name.
One most probable reason for this is you have not added API key in the project manifest file. Simplest way to fix this is go to the "google_maps_api.xml" file and copy the link in the file and paste it in the browser. Click on the create button in the link and copy the api key that is being generated after that and paste it in the AndroidManifest.xml in the place of "Your Api Key" which is inside the meta-data tag, compile the project this will fix the issue.
May be this is because of the Google API key you have to make put google_maps_api.xml file in the values folder and paste the correct API key in it.
and also you have to put this code in AndroidManifest.xml file
<application>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
</application>
If above all answers do not work at all .Then use another Emulator . It worked for me.
If you create the key using the link in google_maps_api.xml it sets the package name of the MapActivity and not the package name of the application (defined in manifest).
Make sure you have the same package name console.developers.google.com as in application manifest.
It can happen because of your key has not restricted yet. after you created your API key, you should restrict the key.
https://console.cloud.google.com/apis/credentials

Enable communication between two Android apps via custom permissions

One of my Android applications needs some features that are "dangerous" when it comes to permissions. They require some permissions such as "Internet access" which are critical in combination with private data.
This is why I want to create a separate "Add-on", i.e. a second app that provides these permission-critical features. So if users want them, they can install the add-on, but the main app will still work without those permissions.
Using a sharedUserId would obviously be the easiest solution, but adding this afterwards, when lots of users use the app already, could cause serious problems. Wouldn't this mean that the app can't access its own data any longer?
So I have to choose another approach. ContentProviders are something that I try to avoid, because they're too complex for this simple need in my opinion.
I thought custom permissions could solve the issue. Can they? I've added the following permission declaration to both the main app as well as the add-on as a child to the manifest tag in AndroidManifest.xml:
<permission
android:name="com.my.package.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
Furthermore, both manifest files have got this part now:
<uses-permission android:name="com.my.package.ADDON"></uses-permission>
The add-on app includes an IntentService that has the following attribute now:
android:permission="com.my.package.ADDON"
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Intent addonIntent = new Intent();
addonIntent.setClassName("com.my.package", "com.my.package.MyService");
startService(addonIntent);
Unfortunately, this call always fails with the following exception:
E/AndroidRuntime(16721): java.lang.SecurityException: Not allowed to start service Intent { cmp=com.mypackage.addon/.MyService } without permission com.mypackage.permission.ADDON
What did I do wrong? Thank you very much in advance!
Addition #1 - Add-on manifest:
<?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.mypackage.addon">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:permission="com.mypackage.permission.ADDON"
android:exported="true">
<service
android:enabled="true"
android:name=".MyService" />
</application>
</manifest>
Addition #2 - main app manifest:
<?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.mypackage.mainapp">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="com.mypackage.permission.ADDON"></uses-permission>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:name="MyApp">
<activity android:name=".MainActivity" android:launchMode="singleTask" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Wouldn't this mean that the app can't access its own data any longer?
Correct.
I've added the following permission
I would dump the permission-group, as that should not be necessary.
Furthermore, both manifest files have got this part now
Only the one calling your IntentService might need that.
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Not if that IntentService is not exported. Make sure that your IntentService either has an <intent-filter> or android:exported="true". I would recommend going the <intent-filter> route, so you can declare and use a custom action string, so you get away from hard-coding package and class names in the client app.
Here is a directory with two sample projects using this basic approach, though in my case the communications are based on a secured ContentProvider rather than a secured IntentService. The concept is the same, though, and so with these minor tweaks, I would expect what you are doing to work just fine.

Categories

Resources