How do I use multiple packages, such as location and maps? - android

First of all sorry, I'm not familiar with the terminology.
I'm following the official Android tutorial and I'm already stuck on the first section of "Making Your App Location-Aware".
I'm following from the very first tutorial and I'm stuck on the first step.
This is what the tutorial says to do,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms.location.sample.basiclocationsample">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
but I already have,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=com.example.user.myapplication.MainActivity">
I'm confused as what to do. I've tried just putting the package separately, e.g.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms.location.sample.basiclocationsample" >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<activity android:name="com.example.user.myapplication.MainActivity">
But even then in MainActivity.java apparently FusedLocationProviderClient has an error - it says 'class' or 'interface' expected.
How would I go about fixing this, and how would I use, say 3 packages?

CommonsWare's answer is correct. However, his answer doesn't help you much. What the tutorial MEANS is to add the line:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
right after the line:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR_PACKAGENAME_HERE" >
You don't need to change your package name to fix the problem, just replace com.google.android.gms.location.sample.basiclocationsample with your current package name com.example.user.myapplication.MainActivity
Warning! If you plan on publishing your app to the Play Store, use some thing other than com.example.user.myapplication.MainActivity
A great example of a good package name for you is com.michaelluong.myapplication

How would I go about fixing this, and how would I use, say 3 packages?
You can't. An app has one package name (a.k.a., application ID).
Generally, when using tutorials, you have two choices:
Follow them to the letter, or
Do your own thing in parts, relying upon your experience to bridge between what the tutorial suggests and what you are actually doing
In your case, I suggest you choose option #1. What you have already has issues (while com.example.user.myapplication is a fine package name, com.example.user.myapplication.MainActivity is an odd choice at best).
If you create a new project, when it asks for the package name, fill in com.google.android.gms.location.sample.basiclocationsample to match the tutorial.
However, do bear in mind that the "tutorials" that you are following are incomplete, skipping steps along the way. Despite their name, most of those "tutorials" are not suited for newcomers to Android.

Related

Where to add IsMonitoringTool meta-data flag in android manifest

In order to meet google's recent stalkerware policy, developer needs to add isMonitoringTool flag if application collecting certain sensitive user data using app. Can someone help me to define this flag in the manifest.
Here is the document where they have mentioned to do so,
https://support.google.com/googleplay/android-developer/answer/12253906#stalkerware_preview
Thanks in advance.
This is a guess, since I cannot find any meaningful documentation at all. And at this point, I don't even know how to test the theory. But I'll offer my guess anyway.
I'm going to guess it goes inside your application node. Like this (only your manifest probably has a ton more stuff in it):
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<application>
<meta-data android:name="IsMonitoringTool" android:value="true" />
</application>
</manifest>
My guess is based on the fact that I inherited a manifest with other meta-data nodes in that location. Of course, it also has meta-data nodes under each activity node, but that location doesn't really seem to make sense for this flag.
What's more, the documentation you linked to says that the "app" needs to use the flag, so that matches putting it under the application node. So there is my unverifiable guess. I suppose we'll find out if I'm right on November 1, 2022, when this becomes required for relevant apps.
https://support.google.com/googleplay/android-developer/answer/9934569
Unless someone who works for Google wants to chime in...?
You can see the extensive search results (!) that a Google search gives me:
The actual correct answer, as per google documentation is
<manifest
<application android:isMonitoringTool="parental_control">
…
</application>
</manifest>
The available options are as follows:
parental_control = App caters to parental control and is specifically targeted at parents who want to keep their kids safe.
enterprise_management = App caters to enterprises who want to manage and track devices given to employees.
other = App that does not fall in any of the above categories. The Google Play enforcement team will assess whether apps with this value qualify for any valid exemption categories.

How to find source of a permission in an Android app?

My users are complaining that my app now requires "run at startup" permission according the listing on Google Play. I have no need for this permission so would like to remove it from my app. I assume it must be from a library that I use but which one? In the "Merged Manifest" there is nothing about "boot" or "startup". I just have these:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
How can I track this down? My users are acting like I'm the anti-Christ for having this extra permission and I look stupid(maybe accurately) for not knowing why. Also, is there a list somewhere that shows what permissions correspond to what text on the Play store description page?
I want to address the comment about removing the permission. I understand how that is done and that's not what I'm asking. I need to know how to find the permission. Else, how can you remove something if you don't know what is is? Also, I may want to keep the permission but need to explain what it is for to my end-users.
#Mike is probably correct about WorkManager API. Still the question is how did he find that out? Why doesn't Android Studio show the permission in the Merged Manifest?
Also, even stranger is that I have removed the WorkManager API so the permission should be gone. I did check out the code for the released version and there are no left over references to WorkManager.
The easy way is from Android Studio. First build your app. Then from the build menu select Analyze APK. From there you can see the full AndroidManifest.
https://developer.android.com/studio/build/apk-analyzer
In my case the permissions did not show up in the Merged Manifest tab. Could be a bug. I think what happened is that I used a library during beta testing. Removed the code that uses library but still had a reference in build.gradle. That added the permission to the released apk's Manifest.

CardEmulation.registerAidsForService not working

I am working on an Android HCE application and I would like to dynamically add AIDs at runtime for a given service. Fortunatelly for me Android API 21 has added the method CardEmulation.registerAidsForService() specifically for that.
Unfortunatelly I cannot make it work no matter what.
I have tried to register both a HostApduService and a normal Service, but the method always returns false.
I can't figure out what the correct approach is as the documentation is quite scarce and I couldn't find any working example.
Registering a service statically for an AID group worked for me so I figured that it shouldn't be a HCE problem, a permission problem or a problem with the device itself (a Note 4 N910C).
I don't know what other approach I should take.
Any information would be great.
Thanks.
Fixed it myself.
It seems bo be working with an HostApduService but I omitted to add the following line to the manifest file:
<meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="#xml/apduservice"/>
In my stupidity, I thought it might be useless for dynamic usage. For those interested xml/apduservice.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="#string/servicedesc"
android:requireDeviceUnlock="false">
</host-apdu-service>
Unsurprisingly, the code is similar to the one in the sample here.

Package changes not taken, even after new name in Manifest

i made a little mistake, i published(started the process, now its waiting to publish) my app name with the first package i created, so i chose to change everything and publish again with the new name, but google play keep saying that the OLD is already in use, but i cant understand, i already made the changes and dont want to use the old...
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.HereComes.theNewPaCkage" >
but it keep saying that the old com.HereComes.TheOldPaCkage is already in use, if i open the project folder and try to search for the term TheOldPaCkage nothing shows, doesnt it mean that there is nO reference to the old package? why google keep saying that i want to use the old...
is there any other file i have to change?
I have faced this before.
In it's solution, what I have done is just remove the previous package from Google Play, then I tried to upload new one.
After that my problem was solved.
You can try this way.

Android Maps V2 keeps crashing

First I want to reference my "research". I'm new to the Android environment, not to Java, but I could say I've sometimes failed to understand the concepts that lead to logical errors. It's been my experience that I usually don't have to think too much about setup, diving right into code. It's also been one one of the things that have held me back.
This to say that the error I'm experiencing now may be because of a fundamental misunderstanding of the compiling-linking mechanism on Java or on Android specifically. I want to change that.
Primarily this question is for an explanation on this subject, concentrating on learning enough to update this text so that I can give an apt explanation of what's really going on and why I was stuck with this problem for so long.
Specifically, I'm using the demo app to test on my device, having the app go "Unfortunately, has stopped". I've followed each step outlined here with repetition and variance in each case following previous answer, especially this answer, which seems to describe a very similar scenario to mine.
I could use a quick fix, but this answer I think deserves a better explanation. Solutions associated with this question seem to depend on what exactly the user has in his environment/the order with which libraries are compiled/the folders within which these libraries are placed. So if anyone has a deeper understanding of what exactly is going on here I would certainly appreciate the visualization.
I can share my own code files (which are copies of the my_location_demo) but I have no logcat as I'm exporting to dropbox to test on my own device.
UPDATE
Does anyone know if I need to declare my library resources in my manifest file? Here it says to declare all external library activity. My current manifest file includes the following:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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"/>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCvGBr5in13NK2yYBR7lhXTtnxj3mrXQy4"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I am looking into the logcat suggestions, although I do not have a rooted device, nor one running <=4.1 But I had this running a while back, this cannot be so difficult.
UPDATE 2
Right now I got the demo app functioning, this is what I did:
1.Created new workspace.
2.Imported Google Play Services lib (Copy into workspace because i have 2 Drives, this only works when both files are in the same drive)
3.I noticed that androi v4 support library was already added.
4.Changed API key accordingly on manifest (which already had all necesary permissions).
Since this was the demo app it already has some setting i cannot decipher. I obviously want to apply this to my own app.
I tried reproducing the same procedure and i noticed the file icon (to the left of the name in the file explorer on eclipse) was missing a symbol for Library, in contrast to my previously succesful demo project.
I referenced that through "Add JAR" in the Java build path libraries tab.
With these options my app gets to a loading map, but crashes before it shows anything.
I referenced the google play through "Add External JAR" in the java build path libraries tab as well, and I didn't get to the map, which takes me "further" away, so I removed it and got the map to 'almost' load again, at least.
UPDATE 3
In the next Image I'd like to point out the only difference I can still find while comparing the demo app (working) with two versions of my app. The bottom red rectangle highlights what I mean about the working project having an android-support-v4.jar with a library icon on its left. The next red highlight box shows one of the project instances I have, where the file is shown to not have the same library icon on its left. The last two red boxes from bottom up highlight how I tried to convert that file into a library, the top red box being a new 'file' that appeared when I made the reference to the library.
The one that 'seems' to work (gets to map controls, but shows no map and crashes) is the top instance.
UPDATE 4
I added this line GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); to my onCreate as suggested here. Which resulted in getting to actually load a MAP (omg im so close) with controls. GPS icon on the top system tray is flashing (acquiring location) and a colorful map appears on the grid, but it still crashes after 5-7 seconds.
UPDATE 5
It's possible that I may have acomplished something, but I think i just lost my time. I added a TextView that was present in the initial tutorial (i didn't need it) to the code and now everything is working (almost fine). I'm guessing I haven't read enough of Layouts to understand how much that needs to be set up.I still have some bugs but at least i can see the map and it's pinging my location.
Again,
Many thanks.

Categories

Resources