I have a problem and I need to know how does the firebase config gets the region/country for a user, is the region based on google account, or what ? also how does it get the region without any permission ?
I have met the problem when I try to get the device region. Here are many ways to get this region, you can use below ways:
use "ro.carrier" get the cid;
use Locale.getDefault().getCountry() get the short country name;
use (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE) to get the region of SIM card.
you may use all of them and given priority.
For Firebase, I have met a short code below, maybe this can help you:
String feature_url = "feature_config";
Log.d(TAG, "init, feature_url: " + feature_url);
mRootReference = FirebaseDatabase.getInstance().getReference();
mRootReference.child(feature_url).child(BuildConfiguration.DEBUG ? "debug" : "release")
.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, "onDataChange");
FeatureConfig.getInstance().updateConfig(dataSnapshot);
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "onCancelled");
}
});
this ie a method used to get the DataSnapShot and then get the region information from it.
Since I dont know whether this could help you, I dont past to much code here.
Hope it helps.
This may give you some idea!!!
You have your own FCM key is strictly required for native implementation.
While setup to get FCM key user should provide region/country
How to set up your own FCM keys:
1) Log in with your Google Account
Open https://console.firebase.google.com/ and log in using your Google account (if the page asks you to do so).
2) Click on Create New Project
In the next box that appears, click on Create New project.
3) Compose the Project Name and select your country/region
You’ll now be prompted with a modal box like the one shown below. Under Project name, write the name you want and below that, select your Country/region. Once you’ve done this, click on the Create Project.
For detail go through this
Related
I'm creating an app on Android Studio with Java and Firestore that lets users make publications and show them on a Fragment with a RecyclerView. The users create a profile (name, avatar) that gets saved in a document named after the user UID inside a collection named "Users". The publications are saved into another collection named "Posts" (title, content, picture, avatar, name).
I wrote two queries, one to get the title and content from the posts from the "Posts" collection, as well as the UID, to then do the other query that gets the name and picture from the poster and then all of those fields go inside a "Post" object and sent to the ArrayList that fills the RecyclerView.
Problem: The posts load perfectly on the RecyclerView but the user picture (the one I'm getting from a different collection) is giving me lots of problems. Sometimes it loads, sometimes it doesn't, and sometimes it loads only for the first post or even the first three posts. I don't understand what could be wrong. I'm posting the code:
private void loadPosts() {
Query postQuery = collectionReferencePosts.orderBy("timestamp", Query.Direction.DESCENDING);
postQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot> task) {
for (QueryDocumentSnapshot document : task.getResult()) {
Post post = new Post();
post.setTitle(document.getString("title"));
post.setContent(document.getString("content"));
post.setImage(document.getString("image"));
String posterUid = document.getString("useruid");
DocumentReference docRef = collectionReferenceUsers.document(posterUid);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
#Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
post.setName(documentSnapshot.getString("name").toString());
post.setAvatar(documentSnapshot.getString("image").toString());
}
});
postList.add(post);
postAdapter.notifyDataSetChanged();
}
}
});
}
If you want to display post details, along with user details at the same time, then you have to notify the adapter about the changes when the second request for getting the name and the image is complete. So you have to move the following two lines of code:
postList.add(post);
postAdapter.notifyDataSetChanged();
Right after:
post.setAvatar(documentSnapshot.getString("image").toString());
Besides that, there is another option that you should consider using, which is called denomalization. This means that you can add the name and the image of the user inside the post document. In this way, there is no need to perform the second query, since all the data already exists inside the post document. If you're new to NoSQL databases, this might sound some kind of weird, but I assure you it's quite common practice.
Please also note, that neither solution is better than the other. According to the number of changes that can occur in your app, regarding the update of name and user image, you have to check which solution is better to be used inside your project.
You can also take a look at the following post to have a better understanding of the asynchronous nature of Firebase API:
How to return a DocumentSnapShot as a result of a method?
I'm a newbie with Firebase and I implemented it in my earthquake sensing Android app. My structure looks like
So, everytime my app senses an earthquake it makes an entry in Firebase like above. What I want to do though is use data from other devices as well to determine if the earthquake was legit or not. Specifially, every time 1 device senses one, I wanna check the firebase if in the last minute there was another entry from another device as well (ideally I would want to also check the coordinates to see if it's at a nearby location but I saw that this is more tough to accomplish so you can skip that). Any idea of how this is possible? Basically, I just want to check if new entries within 1 minute of my entry exist (I could also make a check after 1 minute, in case my device was the first to detect it).
Thanks a lot in advance.
Firebase Realtime Database queries are a multi-step process:
Order the data on a specific property value.
Determine a start node and/or end node to return (sometimes called a slice).
Optionally limit the number of nodes to return.
In Android that'd look something like:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Earthquakes");
Query query = ref.orderByChild("timestamp").startAt("2020-11-03 18:12:00").endAt("2020-11-03 18:12:59").
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot quakeSnapshot: dataSnapshot.getChildren()) {
Log.i("DB", quakeSnapshot.getKey());
Log.i("DB", quakeSnapshot.child("eventType").getValue(String.class));
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
}
I highly recommend reading the Firebase documentation on reading and querying data, and taking the Codelab for Android developers.
I am working on an app that fetch the data from Blogger using Google Blogger API. but the problem is every time user open the app it will fetch the data and show it. I want that the data must be stored on the first time the app is opened and have a option of refresh button, when clicked on that button it will refresh the data and again save it offline.
Here is the code for my getData method in main activity:
private void getData(){
Call<PostList> postList = BloggerAPI.getService().getPostList();
postList.enqueue(new Callback<PostList>() {
#Override
public void onResponse(Call<PostList> call, Response<PostList> response) {
PostList list = response.body();
recyclerView.setAdapter(new PostAdapter(MainActivity.this, list.getItems()));
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
#Override
public void onFailure(Call<PostList> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure", Toast.LENGTH_SHORT).show();
}
});
}
PS: I want to create a tutorial type app with this. Is it a good approach for creating tutorial apps. I find everywhere but did not find the exact solution, So thought to create it by blogger.
You can save data locally in SQLite and use a DAO to make things easier, or investigate SqlDelight and SqlBrite if you want some Rx solutions. There are also storage solutions like Couchbase which are nosql. Finally, you could store the data in shared preferences or even use the file system directly, although I wouldn't advocate for either of those in this case
I have implemented Google Maps in my App and doing reverse geocoding when clicking on map.Im using This API. but it gives me more than one result on Single tap. I know why Google behave like this.
Then I look into PlacePicker widget for Android, but Im unable to use that widget without opening another Map screen to pick place.
What I want is that I want to use my Google Map screen to get tapped place instead of opening PlacePicker screen. I just want PlacePicker work with my implemented Map i.e want PlacePicker to respond map click and give place without opening widget if this is not possible then inform me about other solution to get exactly one and correct place on Map tap? Thank you in advance
Updated
Why Im getting closed vote for question? it is not too broad? Simply,I want to know whether is it possible to use Google Map (MapView|SuportFragment) as PlacePicker's main screen. Have look code below
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
// I don't want this line, Don't want PlacePicker to open another Map Screen to allow user to pick place.
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
now look at below code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
above code is executed when user pick a place from PlacePicker screen and that screen returns a Intent with picked place. Is there any way to make that type of 'Intent' on Google Map tap with lat,lng? so that I could get Place detail. I don't want to user reverse geocoding as it gives me many results.
I Donot know anything about the google geo api or PlacePicker api.
The google independent android standard way would be to use "ACTION_PICK" with a geo uri.
For more infos see https://github.com/k3b/k3b-geoHelper/wiki/Android-Geo-howto.
This only works if you have installed a geo-pick-aware app that supports geo-pick.
Note: you do not have to use the lib. All you need to do is to decode the geo-uri returned by activity result
I have found solution to my problem, To get rid of reverse geocoding to many results and to get clicked place I use following code
googleMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() {
#Override
public void onPoiClick(PointOfInterest pointOfInterest) {
String SS="";
isPOI=true;
poiPlaceID=pointOfInterest.placeId;
// Then using Google PlaceDetail API with placeId, It gives me exact Location click
}
});
In our RCP application we have newly added a menu as command under menu contributions. Now that we want to enable or disable this new menu depending the user who has logged on to the system. Basically we want to enable the menu only for the Administrator login and not for any other user.
How can this be accomplished?
Thanks in advance !!
You can retrieve the logged in user's name as :
String user=System.getProperty("user.name");
You can retrieve the logged in user detail as described in java-forums.org:
public static void ntSystemDetails() {
com.sun.security.auth.module.NTSystem NTSystem = new com.sun.security.auth.module.NTSystem();
System.out.println(NTSystem.getName());
System.out.println(NTSystem.getDomain());
System.out.println(NTSystem.getDomainSID());
System.out.println(NTSystem.getImpersonationToken());
System.out.println(NTSystem.getPrimaryGroupID());
System.out.println(NTSystem.getUserSID());
for (String group : NTSystem.getGroupIDs()) {
System.out.println("Groups " + group);
}
}
If you get an error like this :
NTSystem is not accessible due to restriction on required library ...
then , follow the following steps as described in https://stackoverflow.com/a/2174607/607637
To know about Well-known security identifiers in Windows operating systems, see this page http://support.microsoft.com/kb/243330
Then
I hope that you get enough hints.
You may try using the activities mechanism for this. Have a look at this