The simple answer is yes, you can create a key within an app - there are several libraries to do this in the Java domain, for example, mostly built on the Java JCE Api standard:
There are options around how you use the library and provider, and there are also standalone cryptography libraries most notably BouncyCastle, and it's Android derivative SpobgyCastle:
There is a slightly old but very nice answer here that gives a good background on Android: https://stackoverflow.com/a/9965964/334402
There is a good note in the Java Cryptography document above, also:
WARNING: The JCA makes it easy to incorporate security features into your application. However, this document does not cover the theory of security/cryptography beyond an elementary introduction to concepts necessary to discuss the APIs. This document also does not cover the strengths/weaknesses of specific algorithms, not does it cover protocol design. Cryptography is an advanced topic and one should consult a solid, preferably recent, reference in order to make best use of these tools.
You should always understand what you are doing and why: DO NOT simply copy random code and expect it to fully solve your usage scenario. Many applications have been deployed that contain significant security or performance problems because the wrong tool or algorithm was selected.
You'll find this echoed in many cryptography texts also - essentially it is saying that your security is only as strong as the weakest link, and there is a danger of adding cryptography to an app and thinking everything is then fine.
An easy to understand example of the weakest link is if you generate a very strong private/public key pair, but then have weak security around the private key itself allowing a hacker debug your application to discover it.