android error: IllegalStateException: Only fullscreen opaque activities can request orientation - android

I have an activity that open from browser when Device is in Landscape get me below error
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
Manifest
<activity android:name=".Activity.MyActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Theme_Slide"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="xxx"
android:scheme="xxx" />
<data
android:host="xxx"
android:scheme="xxx" />
</intent-filter>
</activity>
style.xml
<style name="AppTheme.Theme_Slide" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>

UPDATE FIND SOLUTION
In android Oreo (API 26) you can not change orientation for Activity that have below line in style
<item name="android:windowIsTranslucent">true</item>
You have two way for solving this :
You can simply remove above line (or turn it to false) and your app works fine.
Or you can first remove below line from manifest for that activity
android:screenOrientation="portrait"
Then you must add this line to java file
//android O fix bug orientation
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Related

My Android App shows up twice in list when sharing from the Photos App

My Android app has the ability to receive both URL and Image shares from other apps. The following extract from the manifest shows the definition of the two activities involved in handling these shares:
<!-- Activity: Share Handler -->
<activity android:name="com.softframeworks.tabdancer.ShareHandlerActivity"
android:label="#string/shared_browser_url"
android:noHistory="true"
android:windowSoftInputMode="stateHidden">
<!-- Intent filter indicates that this activity can handle text -->
<!-- shared using the SEND action. -->
<intent-filter android:label="#string/app_name" android:priority="777">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<!-- Activity: Image Share Handler -->
<activity android:name="com.softframeworks.tabdancer.edit.icon_cache.ImageShareHandlerActivity"
android:label="#string/app_name"
android:noHistory="true"
android:windowSoftInputMode="stateHidden"
android:parentActivityName="com.softframeworks.tabdancer.ManageActivity">
<!-- Intent filter indicates that this activity can handle images -->
<!-- shared using the SEND action. -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
The problem I am having is that when sharing a photo from the Google Photos app, my app shows up twice. It seems that the intent-filter of both of my activities matches with whatever the Photos app can share to. I would like my app to show up only once in the list of those that can receive shares from the Photo app. Ideally, the share would be done as an image (not URL).
I am testing this on a Nexus 7 running Marshmallow.
Thanks in advance.
I was able to resolve this by changing my manifest to be as follows:
<!-- Activity: Share Handler -->
<activity android:name="com.softframeworks.tabdancer.ShareHandlerActivity"
android:label="#string/shared_browser_url"
android:noHistory="true"
android:windowSoftInputMode="stateHidden">
<!-- Intent filter indicates that this activity can handle text shared -->
<!-- using the SEND action. -->
<!-- Intent filter also indicates that this activity can handle images -->
<!-- shared using the SEND action. However the code for this activity -->
<!-- redirects image shares to the ImageShareHandlerActivity. -->
<intent-filter android:label="#string/app_name" android:priority="777">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- Activity: Image Share Handler -->
<activity android:name="com.softframeworks.tabdancer.edit.icon_cache.ImageShareHandlerActivity"
android:label="#string/app_name"
android:noHistory="true"
android:windowSoftInputMode="stateHidden"
android:parentActivityName="com.softframeworks.tabdancer.ManageActivity">
</activity>
So now the ShareHandlerActivity handles image as well as text shares. However, in this activity's onCreate() method I test the intent's type. If it's image/* then I delegate the processing of the share to the ImageShareHandlerActivity.

AppCompat Theme Error when using NoActionBar

I'm using a toolbar for my entire application. So I have set up my application Theme to Theme.AppCompat.Light.NoActionBar But I need to show a alert dialog in a part of my app. When I try to show alert dialog I'm getting Runtime error about Theme.Appcompat
My manifest.xml file
<application
android:allowBackup="true"
android:icon="#drawable/app_icon2"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
>
<activity
android:name="com.project.project.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.project.project.StActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/app_name">
<intent-filter >
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
What should i do
Thanks for help
It's hard to tell without seeing the code where you actually create the Dialog, but my guess is that you're either:
Not using the Activity as the Context when you create the Dialog. The Activity context holds the theme; if you tried using the Application it wouldn't get the right theme.
Setting your Dialog theme to something that doesn't inherit from Theme.AppCompat (using the constructor, setStyle() or ContextThemeWrapper).
Either way, the Dialog doesn't get the required attributes provided by Theme.AppCompat.

Open invisible activity on share action (ACTION_SEND)

There are a lot of similar questions on StackOverfow but they don't solve my problem.
The task is to process in Service intents sent with default share mechanism (ACTION_SEND) from different applications.
But as far as ACTION_SEND is an activity action we have to pick up intent in activity and broadcast it to service. And it will be perfect if this activity will be invisible to the user.
I've researched a lot and have tried many solutions already.
First step of making activity invisible belongs to activity style.
I've tried this values.
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:theme="#android:style/Theme.Translucent"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Also i"ve tried to create a custom theme.
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
How the activity in AndroidManifest.xml looks like.
<activity
android:name="xxx.xxx.activities.HandleShareIntentActivity"
android:theme="#style/Theme.Transparent"
android:noHistory="true"
android:excludeFromRecents="true"
android:label="#string/title_activity_handle_share_intent">
<intent-filter>
<action android:name="com.google.android.gm.action.AUTO_SEND"/>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.google.android.voicesearch.SELF_NOTE"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
Activity code. No setContentView(). finish() in onCreate().
public class HandleShareIntentActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, xxxService.class).putExtra(
Constants.ACTION_SHARE_KEY, getIntent()));
finish();
}
}
On Nexus 5, android 4.4.4 I do have black screen blink while handling any share event.
Any solutions?
I've tried this values.
Use Theme.NoDisplay.
I Just did this, and it helped in my case:
<activity
android:name=".SensorBoardActivity"
android:theme="#android:style/Theme.NoDisplay"
android:excludeFromRecents="true"
android:noHistory="true">
I see you already have finish(); but just for others it is important to execute it just before leaving the onCreate().

why this screen, while app opens every time

Here I am getting this screen every time just like a splash for few seconds and then opening the home activity.I don't want to this screen in my app. How to fix it.
Here is my manifest file
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.asdf.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For your Information, I am using Support Library for developing.
I changed the app Style to "#android:style/Theme.Translucent.NoTitleBar" then this screen is not showing but It has the impact on other UI components of the same App like.. Spinner, text-view etc.
Add this line in your style.xml
<style name="AppTheme" parent="android:style/Theme.Holo">
<item name="android:windowDisablePreview">true</item>
try this..well previous one should work.It worked for me
If you want to remove the title bar, then use the following in your Activity initialization:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
...
move Intent-filter code to whichever activity of your application. and remove that activity code.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Hope it will work

Every Activity of my application is shown as an app on its own

Just like the title says, for some reason which I dont understand, Every Activity I create in my application is shown as an icon for an application on the phone's app menu.
Could someone please help me solve this wierd problem?
If you need some code just ask for it (I dont know which code is related with these kind of stuff).
Thanks!
In your manifest remove these lines from all Activities except the one you want to open on:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Example:
<activity
android:name="your.package.name.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<!-- This line declares this Activity as the start point -->
<action android:name="android.intent.action.MAIN" />
<!-- This line adds a launcher icon -->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="your.package.name.OtherActivity"
android:label="#string/app_name" >
</activity>
In your manifest file you must have set launcher intent-filter for all of your activities.. Keep launcher intent-filter only in launcher activity..

Categories

Resources