I have an Android app build with the newest version of Android Studio.
I want to allow only portrait mode on phone but all orientations on tablets.
I followed this answer and also this post.
I made everything as described.
Then I opened the file activity/MainActivity.java.
I looked for this line of code: public void onCreate(Bundle savedInstanceState) {
Then I added the following code below this code:
if(getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Here's a small snippet:
#Override
public void onCreate(Bundle savedInstanceState) {
if(getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityInfo has a red color with the following error message:
Cannot resolve symbol 'ActivityInfo'
It also shows a blue information:
android.content.pm.ActivityInfo? ⌥⏎
Why that? What am I doing wrong?
You need to add the following line at the top of your file below package name to import ActivityInfo:
import android.content.pm.ActivityInfo;
Related
My Android project show that it is not able to find the android.view.View class but still it is being compiled and run on simulator and devices.
apart from android.view.View All other class of the package is accessible like
This is not available ==> import android.view.View;
this is available => import android.view.ViewGroup;
I have tried many things like Clean, Rebuild, restart and Invalidate cache and restart but not fixed this issue.
Please check the code and help me to fix this issue.
import android.view.View;
public class AppSettingsActivity extends BaseActivity implements View.OnClickListener, AdListener {
//Other objects
private static final String TAG = AppSettingsActivity.class.getSimpleName();
//Data objects
// //Design
private LinearLayout banner_container;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
initViews();
}
private void initViews() {
//Actionbar init
//Action bar
TextView idTvTitle = findViewById(R.id.idTvTitle);
findViewById(R.id.idTvSelectDefaultActivity).setOnClickListener(this);
findViewById(R.id.idTvSelectAppLang).setOnClickListener(this);
findViewById(R.id.idIvBack).setOnClickListener(this);
findViewById(R.id.idTvCalcSetting).setOnClickListener(this);
//Set data
//Set Actionbar Title
idTvTitle.setText(R.string.app_settings_text);
//Load Facebook ads
banner_container = findViewById(R.id.banner_container);
if (fbAdView != null) {
banner_container.addView(fbAdView);
fbAdView.loadAd();
fbAdView.setAdListener(this);
logs.e(TAG, "Face book load add called....");
}
int selectedLanguage=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.SELECTED_LANG, AppConstant.INT_ONE);
int selectedScreen=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.DEFAULT_SCREEN_INDEX, AppConstant.INT_ONE);
String[] languages = getResources().getStringArray(R.array.language);
String[] screens = getResources().getStringArray(R.array.screens);
((TextView)findViewById(R.id.idTvSelectDefaultActivity)).setText(screens[selectedScreen]);
((TextView)findViewById(R.id.idTvSelectAppLang)).setText(languages[selectedLanguage]);
}
I am giving this answer to my question.
I simply uninstall the Android studio and reinstall it. My previous Android studio was running with 3.5 version (Latest) and the fresh install Android studio version was also 3.5 so there was no versioning difference in it. But I don't know some How issue fixed when I reinstall AS.
After half an hour of searching, I could not found a solution that can fix my issue. Then I pass the same code to other PC and it was working well on that PC.
So This is final that no issue in the source code.
Then 2nd suspect is the android studio
I uninstall Android Studio and install it again, it took me 1 hour to set-up and make the code workable but it saves 30GB of my hard disk space so it was worth it.
But still, Android studio manage SDK and build tools very badly
I've a little problem with android studio. Until yesterday I used Eclipse. But today I start to use Android studio. I write a simple layout without errors. Than in src/main/java I write this simple code:
public class MyActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(android.R.layout.activity_my);
}
}
But I've an arror: "cannot resolve symbol activity_my"
According to me the layout isn't registrated in R.java. How can I resolve this problem? Thanks in advance :D
p.s. sorry for my bad english >.<
Use R and not android.R. Check that the imported R is your.package.name.R.
you should always use setContentView(R.layout.activity_my);.
so replace setContentView(android.R.layout.activity_my); with setContentView(R.layout.activity_my);
USE CTR + SHIFT + o to organize your import statements in eclipse.
package com.phonegap;
import org.apache.cordova.*;
import android.os.Bundle;
public class PhoneGapSampleActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("assets/www/index.html");
}
}
I use this code for PhoneGap application..
But it shows an error.
I added index.html file in assets/www folder.
But it shows an error ...
Anyone can help me??
Thanks in advance.
You forgot the file:///. Keep in mind it's important to have the three slashes!
Also I think it should be android_asset and not asset.
In my app it is: "file:///android_asset/www/index.html"
Simple Google search came to this :
phonegap doesn't work
The solution was to rename phonegap.0.9.4.js and phonegap.0.9.4.jar to just phonegap.jar and phonegap.js.
I have developed Android applicationusing Phonegap framework with Eclipse pulgin. am not gettting any error in Eclipse but when i'm running the app am able to see the blank app screen.So can someone help me out this issue..
Sample app developed using this link
Please comment asap..
Code:
Java File ----------
package com.phonegap;
import com.phonegap.*;
import android.os.Bundle;
public class HelloworldActivity extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_assets/www/helloworld.html");
}
}
The problem is in your loadUrl, you should use:
super.loadUrl("file:///android_asset/index.html"); // Singular android_asset, not assets
I am using gradient as background in my activity. on some android devices it doesn't look as good and smooth as in Photoshop, to fix this issue somebody told me use onAttachedToWindow() method.
I checked Android page (http://developer.android.com/reference/android/app/Activity.html#onAttachedToWindow()) and I found that this method is a part of android.app.Activityand I wrote following lines of code:
package com.test.test1;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
public class Mainctivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
}
but when run the emulator, it crashed and in DDMS I saw this error:
11-25 10:48:13.353: E/dalvikvm(216): Could not find method android.app.Activity.onAttachedToWindow, referenced from method com.test.test1.MainActivity.onAttachedToWindow
What is my fault?
This method is available since API Level 5. What version of Android is running on the emulator?
As per the comments above, I've had this code tested on an actual device and it worked smoothly. So this is an emulator problem. Hopefully this will be resolved in later versions of the sdk.