I'm unlocking achievement using this simple method from developers docs:
Games.Achievements.unlock(getApiClient(), "my_achievement_id");
Achievement unlocks, but no popup shows up. There is also no popup when logged in to Google Play Games - which is connected.
Just add a view to the layouts you want to display achievements on like this:
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
When you have your layout ready you neet to execute this inside your Activity or Fragment:
Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup));
You have to be sure, that your GoogleApiClient is connected though, otherwise your app will crash.
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
This is the same in Jacek KwiecieĊ answer
GamesClient gamesClient = Games.getGamesClient(MainActivity.this, GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));
This changed because setViewForPopups with 2 parameters is deprecated.
Jacek and user3782779 answers didn't work for me, I had to do the following:
GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
Had the same problem. I have solved it by adding icon to the achievement. I am not kidding, it is really strange but it started to work after that. Please note that I am talking about not published project, I was just testing my app and wondering what is going on.
The ONLY view that worked for my case of having multiple activities was:
activity.window.decorView.findViewById(android.R.id.content)
I had the same problem with the achievement popup. The "Welcome Back" popup was showing correctly by just using my own View, but once I started opening other screens where I wanted to show the achievement unlocked popup, it was not working. The only thing that ended up working was using the content view from the decorView
val gamesClient = Games.getGamesClient(activity, googleSignInAccount)
gamesClient.setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
gamesClient.setViewForPopups(activity.window.decorView.findViewById(android.R.id.content))
You can call this code from any new activity you open and the pop-up will show up there as soon as you unlock your achievements.
Related
I want to show VR tour like this http://alfavr.ir/alfavr.ir/to/park.html in my Android app.
how can I do that?
I tried to display with web view because the file format is Html but did not work.
You can try with VRPanormaView which is included in the Google VR SDK. This is an example from https://developers.google.com/vr/develop/android/vrview:
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:id="#+id/pano_view"
android:layout_margin="5dip"
android:layout_width="match_parent"
android:scrollbars="#null"
android:layout_height="250dip" />
Inside the Activity, the primary method is VrPanoramaView.loadImageFromBitmap(). Call it with a standard Android Bitmap object and an optional VrPanoramaView.Options object. The latter is used to configure the format of the image. The Activity also implements a VrPanoramaEventListener which receives events when the load operation succeeds or fails.
Adding this line make It work.
webView.getSettings().setJavaScriptEnabled(true);
This is probably a basic procedure, and in fact I've been extensively searching for a suitable answer, but I haven't found anything usable or that actually works. Now, the case:
A Dialog window is placed inside a method:
public void method_with_Dialog_code() {
Dialog simpleDialog = new Dialog(this, R.style.FilterDialogTheme);
simpleDialog.setContentView(R.layout.dialog_xml_layout);
simpleDialog.setCancelable(true);
TextView insideTextView = (TextView) simpleDialog.findViewById( R.id.insidetextview );
insideTextView.setText("This text should change when the WiFi is offline");
simpleDialog.show();
}
The respective dialog_xml_layout.xml file is simply:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/insidetextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
If the device is for example disconnected from the Internet, it generates a message that should be shown in the insideTextView. But notice that simpleDialog and insideTextView are inside the method, so they are local objects, so the first issue is how to execute:
insideTextView.setText("This device is now offline");
from another part of the code, that is, outside of the method?
If I decide to make simpleDialog and insideTextView as Global variables, I can with no problem, from another part of the program, set the line:
insideTextView.setText("This device is now offline");
But the instruction doesn't work. The TextView is never updated with the new message.
So, any ideas? Maybe with TextView.addTextChangedListener, so insideTextView could be updated when the TextView.setText is executed externally?
Gracias.
make insideTextView a member variable of the class and use it later.
I recently implemented Algolia on my app successfully just like the examples.
But the initial search takes about 5 to 7 seconds and I couldn't find a way to make it faster after checking the whole library code and documentation. After the initial search, search becomes very fast.
There is nothing unusual in my implementation but maybe you can see something that I don't. The following code is from the activity where I initialize Algolia:
Searcher searcher = new Searcher(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
searcher.setQuery(new Query("word").setExactOnSingleWordQuery(Query.ExactOnSingleWordQuery.ATTRIBUTE));
searcher.addNumericRefinement(new NumericRefinement("CountryId", NumericRefinement.OPERATOR_EQ, 1));
InstantSearch helper = new InstantSearch(this, searcher);
helper.setSearchOnEmptyString(false);
helper.search();
And this is the related xml layout:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingRight="10dp"
android:paddingLeft="1dp"
android:paddingTop="6dp">
<com.algolia.instantsearch.ui.views.SearchBox
android:id="#+id/searchBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="#string/search_text_hint"
algolia:searchIcon="#drawable/icn_search_big"
algolia:closeIcon="#drawable/icn_clear_filled_big"
android:queryBackground="#drawable/sarch_query_shape"
android:background="#drawable/search_shape"
algolia:autofocus="true"
algolia:submitButtonEnabled="false" />
</FrameLayout>`
<com.algolia.instantsearch.ui.views.Hits
android:id="#+id/hits"
android:layout_width="match_parent"
android:layout_height="match_parent"
algolia:autoHideKeyboard="true"
algolia:hitsPerPage="6"
android:layout_below="#+id/searchBarParentLayout"
algolia:infiniteScroll="false"
algolia:itemLayout="#layout/search_item_algolia_row"/>
Do you have any idea what can be the issue here?
I'm glad that the issue disappeared when you switched to another wifi.
For future readers that may encounter network issues with InstantSearch Android:
First of all, build and run one of our demo applications
If you see no problem running the example application, you can try using a proxy like Charles to investigate what's happening between your app and the network
If your problem persists when running the examples, or if you are following the documentation, send an email to support#algolia.com describing the issue with a sample of your code!
I followed the standard procedure to add a Google plus button:
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="#+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
plus:annotation="bubble"
plus:size="standard(none)" />
It is linked to the app's Google Play page. It is initialized in onResume as recommended:
_PlusOneButton.initialize("https://play.google.com/store/apps/details?id=net.mydomain.myapp", 0);
The button gets the count correctly initially, but the count never changes. The Google Play page shows the count keeps changing (increasing) as expected. I have been curious about activityRequestCode in initialize (String url, int activityRequestCode). I do not know what it does.
Could anyone shed some light on this?
I want to use Admob in my app. I've downloaded the SDK and followed the steps. Sometimes, I get an ad in return, but most of the time, I get an entry in LogCat that says "Server did not find any ads" or something to that effect. Test mode is enabled, says the Admob site. I think I might be doing something wrong. Where can I get a step-by-step guide to insert admob ads in Android apps? The Admob developer site is rather lacking.
Also, let's assume that everything's gone well and that I'd now like to deploy the app. How do I turn off test mode for Admob ads?
Thank you.
Download the AdMob jar file http://www.admob.com/my_sites/
Create a package on your project and call it "libs" and paste this file AdMob.jar there
Right click on your project a select the library, add there the path for the ADMOB.jar you just saved.
If you're creating your AdView on your XML, you can add this line.
This is an example for testing. When you get your own ID from ADMob, place it on the adUnitID and erase the test line.
com.google.ads.AdView
android:id="#+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="a14f59e5c442767"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"
</com.google.ads.AdView>
Now go to your .java that it calling this layout and create your AdView
AdView adView = (AdView)this.findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
This is how I do and its been working good so far.
Sorry about bad english, to much code and no sleep!
just follow the instructions on this site:
http://developer.admob.com/wiki/Android#AdMob_Android_SDK
I guess you did not activate the test mode for your device or the emulator?!
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
It seems as though this might have changed to
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("E83D20734F72FB3108F104ABC0FFC738"); // My T-Mobile G1 test phone
see http://code.google.com/mobile/ads/docs/android/intermediate.html
As per Tom's comment below the value to provide for addTestDevice is actually the MD5 hash of the device ID. YOu can get this from the logcat.
Just add a permission to the Android mainfest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Check it once.
Then add this code:
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
You don't need to call it programmatically.
It took me a while until I get what device is AdMob's sdk what expecting cuz' I was thinking it was something related to the real device like ( adb devices )
But here is a comment from the official documentation that cleared it up.
There will be a log message with the code needed to add the current
device to the list of test devices
You may get an message similar to it
I/Ads(26674): To get test ads on this device, call adRequest.addTestDevice("F1254CDFBA84BDC27F5C7C6E12445D06");
All you have to do after that is to place this ID into your layout xml as below
<com.google.ads.AdView
android:layout_alignParentBottom="true"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/publisherId"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, F1254CDFBA84BDC27F5C7C6E12445D06" />
Hope it helps you guys out
Paulo Miguel Almeida