I am working on an augment reality android app. I developed the app in unity using vuforia and then imported it in android studio as i wanted to design it in android studio. The activity name in generated project structure is UnityPlayerActivity which has no layout in the project. The activity is passed to UnityPlayerclass and the layout is generated. This is some code of my UnityPlayerActivity activity.
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
#Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
as it uses that layout how can i design that activity by referencing it.
It is not possible to do this by referencing the object(Java does not support call by reference).
You need to define a new function in UnityPlayer class that generates a layout and returns the LayoutParams object.
Then use the Layout inflator. Something like this:
LayoutParams mParams=mUnityPlayer.layoutGenerator() //some function to generate LayoutParams
LayoutInflator.getLayoutInflator().inflate(LayoutParams);
Finally i found an easy solution to my problem. I displayed the unity scenes in a subview using a framelayout and now i can customize the UI easily. Check here and here to see more information.
Related
I want to know how to show the Unreal screen on Android's subview.
I apologize for my lack of English skills.
I want to show the Unreal screen in subView for Android-based projects.
I want to put it in a project created by a new project through Android Studio.
The start consists of Android native code, and several menus were all created using JetPack api.
Here, I want to configure the bottom with Android UI and the top with an Unreal screen.
Or, if you press the start button for UNREAL screen, I want to render the screen where the entire screen is UNREAL screen.
These two things should possible.
I knew how to do Unity.
Unity knows what is possible.
Is Unreal possible?
If possible, can I get help with the guide links such as documents and videos?
Try this as I assume that you have already added the Unreal Engine Viewport Client plugin to your project and that you have added a LinearLayout with the id
import com.epicgames.ue4.ViewportClient;
public class MainActivity extends Activity {
private ViewportClient mViewportClient;
private SurfaceView mSurfaceView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the Android View to display the Unreal Engine Viewport
mSurfaceView = new SurfaceView(this);
// Add the Android View to the layout
LinearLayout layout = findViewById(R.id.layout);
layout.addView(mSurfaceView);
// Create the Viewport Client and associate it with the Android View
mViewportClient = new ViewportClient();
mViewportClient.SetViewport(mSurfaceView);
// Configure the rendering settings for the Viewport Client
mViewportClient.SetResolution(1920, 1080);
mViewportClient.SetCameraPosition(0, 0, 1000);
mViewportClient.SetPostProcessingEnabled(false);
// Start the rendering loop for the Viewport Client
mViewportClient.Start();
}
#Override
protected void onDestroy() {
super.onDestroy();
// Stop the rendering loop when the activity is destroyed
mViewportClient.Stop();
}
}
I have used Ampiri integration in my app.
I copy paste all the code from their android sdk integration wizard for banner ads into my code. What bothers me is that Android Studio can not find that listener and view in the red letter.
So what is that I miss? Is there any problems on my code? If not what should I do to resolve this issue? Please help me.
Following is my code:
I’ve implemented the AdEventCallback using:
import com.ampiri.sdk.listeners.AdEventCallback;
and call it from main activity inside onCreate as describe in my code below:
public abstract class MainActivity extends AdCallbackActivity implements AdEventCallback {...}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout adView = (FrameLayout)view.findViewById(R.id.ad_view);
StandardAd standardAd = new StandardAd(this, adView,“MY_ADUNIT_ID",BannerSize.BANNER_SIZE_320x50, adListener);
standardAd.loadAd();
Please check my comments inline for each error.
view.findViewById(R.id.ad_view)
If the ad_view is in the current Activity layout set by setContentView, you don't need to add "view."
i.e.
findViewById(R.id.ad_view)
adListener
Please implement an event listener interface AdEventCallback, referencing to our integration page.
In addition, If you will have the AdEventCallback methods in your AdCallbackActivity.java file.
please try the code below.
StandardAd standardAd = new StandardAd(
this, adView, "3dfbb889-3bcd-4c34-82ae-8fcb539c3b25",
BannerSize.BANNER_SIZE_320x50, this);
If it doesn't work, please send me your MainActivity and AdCallbackActivity to suppport#ampiri.com.
I have provided an aplication made in android that has a navigation drawer and in it has a list of games. I have to create another game and to put it there. The game that has to be created by my must use libGDX but the original application didn't use this library.
Is it possible to do this ? If Yes, how can I add the libgdx to the exiting project. On github I found only how to start a new project with libGDx, an not how to add it to exising code. thanks.
You can achieve this with these 2 steps:
1. Add LibGDX to your project
On your android gradle file: build.gradle (app or android module)
dependencies {
...
// Add this line, it is recommended to use the latest LibGDX version
api "com.badlogicgames.gdx:gdx-backend-android:1.9.10"
}
2. Initialize LibGDX for a view or use a LibGDX managed activity
Option 1: Initialize for a view
Since you have a navigation drawer and more code native to android this option fits your needs better. From this question (How to add LibGDX as a sub view in android):
The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.
-- Matsemann
Also here's documentation on how to implement this (Fragment based LibGDX).
Option 2: Use a managed activity
This is the default/most common use of LibGDX, you will need to change your code as follows:
Your activity needs to extend Android application:
public class MainActivity extends AndroidApplication {
Create a class extending Game or ApplicationAdapter:
import com.badlogic.gdx.Game;
public class LibGDXGame extends Game {
#Override
public void create() {
System.out.println("Success!");
}
}
Initialize the LibGDX managed activity:
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new LibGDXGame(), config);
}
}
Generally what you want is possible, I reckon your best bet would be to create a new libgdx project with their GUI and to then manually merge the files that are needed.
I'm trying to implement achievements with Google Play Services in a game. I have followed up the steps in this documentation and everything is ok except I got a runtime warning and then a crush. The warning is:
06-09 10:43:05.900: W/PopupManager(17888): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
My application is using openGL and the activity has a member mView that extends GLSurfaceView.
I have tried this and this (I have all those meta tags and the app_id setup correctly).
Also, TypeANumber starts correctly with my app_id.
Can anyone help me on this?
EDIT [added some code]:
Here is the Activity declaration:
public class GGActivity extends BaseGameActivity implements SensorEventListener, IDownloaderClient {
Here is onCreate where the problem occurs (after the change suggested by free3dom):
public GGView mView;
#Override protected void onCreate(Bundle icicle) {
setRequestedClients(BaseGameActivity.CLIENT_GAMES | BaseGameActivity.CLIENT_APPSTATE);
//if (DEBUG_BUILD)
{
enableDebugLog(true);
}
setContentView(mView); // make sure mView is created before
getGameHelper().createApiClientBuilder();
getGameHelper().getApiBuilder().setViewForPopups( mView );
super.onCreate(icicle);
YES, setContentView helped. Thanks!
In order for your activity to recognize and use the GLSurfaceView you have to set it. This can be done by calling
setContentView(mView);
after creating the GLSurfaceView (documentation can be found here).
I'm writing an application. It needs to run on old android OS's to be useful. I have written the preferences screen using a PreferencesActivity that populates with a options.xml file that contains PreferenceScreen. It has no submenu for preferences (so PreferenceFragment provides no real benefits).
In Android 2.1 (2.2 and 2.3, haven't tested on ICS yet) the screen displays properly like so in landscape:
But on Jellybean, it looks like this:
It looks terrible. I have nothing defined as a layout, just standard addPreferencesFromResource(). Does anyone know what the cause of this might be? Or a solution?
My onCreate looks like this:
protected void onCreate(Bundle savedInstanceState) { //
super.onCreate(savedInstanceState);
Log.i(TAG, "Options Activity Loaded.");
setTitle(getString(R.string.optionsTitle));
addPreferencesFromResource(R.xml.options);
setupListeners();
}
Everything else just makes Preference objects and assigns methods to do stuff when they get clicked. I don't want to make code for both PreferenceFragment and PreferenceActivity. I do not understand how google expects us to use Fragment APIs if the largest version marketshare doesn't have that API and they will not add it to the compatibility lib.
Your application can support both the old and the new functionality for SharedPreferences. You can provide a Class for the old preferences and a Class for the new. Its not much more code. You can make your app backward compatible like this:
Class spc = Build.VERSION_SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
oldPreferenceActivity.class : newFragmentPreferenceActivity.class;
Intent i = new Intent (this, spc);
startActivityForResult (i, SHOW_PREFERENCES);