Android - How to change launcher theme (device theme) programmatically - android

Briefly;
I'm working on a 'Device Production Test' project. We are developing system applications to test whether the API provided by the manifacturer is stable or not.
I need to set Android launcher application theme programmatically and check system level warnings and errors during this process.
I see this question in SO but the source code link is broken.
How can I change Android theme programmatically?
Thanks in advance

You can use this code in manifest file If you really want to launch the activity which I write.
<activity
android:name=".LaunchedActivityName"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// set your custom theme here before setting layout
super.setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);
setContentView(R.layout.activity_main);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

Related

How to pick Activity to start from the launcher based on SDK version?

I have an Android application which has multiple entry points in the launcher.
Some of these requires a higher SDK version than others, and I want to disable or hide these if the device has a lower SDK version than what they require.
Basically my Manifest looks like this:
<application
...
<activity
android:name=".Activity1"
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... // more launcher activities follows
</application>
Activity1 requires SDK version 19, but Activity2 requires SDK version 21. My minimum SDK version is 19.
I want Activity2 hidden to be when installing the application on devices with SDK version < 21.
I know I can do a check in the onCreate method of Activity2 like so:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
finish();
return;
}
...
}
But the activity will obviously still show up in the launcher.
I'm also aware that this is a rather unique problem, and for most people with the same issue, the simplest and probably best solution is to just not have multiple activities as launcher activities, but this will not work so well in my use case.
Please don't do this in code, the only correct way to do this is to use the android:enabled="true/false" property which can be set on components in the AndroidManifest.xml file like an Activity or BroadcastReceiver. Instead of hard-coding the boolean value, use a boolean resource that changes per API level:
values/bools.xml: Both activities are disabled by default
<bool name="activity_1_enabled">false</bool>
<bool name="activity_2_enabled">false</bool>
values-v19/bools.xml: On SDK 19 up to 20 activity 1 is enabled and 2 disabled
<bool name="activity_1_enabled">true</bool>
<bool name="activity_2_enabled">false</bool>
values-v21/bools.xml: On SDK 21+ both the activities are enabled
<bool name="activity_1_enabled">true</bool>
<bool name="activity_2_enabled">true</bool>
AndroidManifest.xml
<activity
android:name=".Activity1"
android:enabled="#bool/activity_1_enabled" />
<activity
android:name=".Activity2"
android:enabled="#bool/activity_2_enabled" />

Android - Custom Home Application Doesn't Appear When Click Home Button

I'am using Android Studio and I have developed an Home Application by adding
<activity
android:windowSoftInputMode="stateAlwaysHidden"
android:screenOrientation="landscape"
android:launchMode="singleInstance"
android:stateNotNeeded="true"
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
This is working and I am testing my application with run button no problem.
But after run another app from Android Studio the home application stop appearing home button selection screen.(not everytime). This is how I solve my problem
I create another application
Move files and codes to new created project.
Then my code is working with different name
This looks like a bug, I dont know what is that. Is there a way to clear cache data or another simple way to solve the problem or any suggestion?
You most likely have a different launcher set as default launcher.
In the settings of your device you should be able to set the default launcher.
Go to applications and look for your current launcher. Clear the default launcher.
If you cleared the default launcher and correctly installed your launcher, it should now ask every time which launcher to launch when you hit the home button.
Tip: Try it out on different devices and emulators!

Application icon does not appear after installing android app

I am developing an android app and when I install the app on android phone, the application icon does not appears in application section. But it appears in application manager and I can make uninstallation. After googling, some said I need to rebuild my project and to make sure the app icon in drawable resource. I already tried for this solution and the problem is still occurring. The manifest file I created is as follow:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.view" />
<data android:scheme="geo" />
</intent-filter>
</activity>
</application>
I believe geo scheme cannot be used with Launcher. I can't find any documentation but in this tutorial they suggest to use with default category.
Please try to move your location related code to another activity and move scheme=geo filter to that one.
In your manifest in activity try using or add another intent filter
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
`
Change
android:icon="#drawable/ic_launcher"
With your icon
if you wanna to remove this icon you have to remove from all folder like
drawable
drawable-hdpi
drawable-mdpi
drawable-xhdpi
I set action android:name="android.intent.action.MAIN and android:name="android.intent.category.LAUNCHER two of mine activity intent.For this I'm having two launcher icon.When I noticed that I remove one activity's intent filter,but My launcher icon disappear.I tried all the mentioned above solution but didn't work.As I noticed Darpan's comment about re-starting your phone will fix it I tried and It works for me
In my case, my manifest included a label for the main activity. I deleted the label, restarted the app and the icon magically appeared in the applications list.

Phonegap Android app restarting instead of resuming

this question was asked 3 times here but no answer.
I´m using Phonegap 2.1 on android device 2.3.6 (Galaxy SII)
I´m also using AdMob Phonegap plugin.
Well the problem is the same as stated by others:
When trying to resume thru the app icon the app is restarted even though it´s in memory
When passing thru the task manager it is resumed normally
My main activity
public class testApp extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html",5000);
}
}
manifest.xml
<application android:icon="#drawable/icon" android:label="#string/app_name"
>
<activity android:name="testApp" android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
/>
</application>
Thank you for any advice
If you have "Do not keep activities" selected in the Developer Options section in the Settings app, then no matter what you configure your manifest to, all activities will be destroyed when not in use by the user. This applies to PhoneGap apps and native apps.
place android:launchMode="standard" in manifest for testApp Activity

runtime errors in eclipse (android development) launch activity: Is there anyway to step through the source in eclipse in windows?

I am trying to make an android game in eclipse (in windows). I keep getting nulpointerexceptions, and classcastexceptions when i run my program both on the emulator and on my phone. I have 2 classes(activities), each with their own xml layout. the main activity runs perfectly. However when I launch the second activity with:
final Intent i = new Intent(this, Arrowscreen.class);
...
startActivity(i);
I get the previously mentioned exceptions. It always points to the source, which is not found. Is there anyway to step through the source in eclipse in windows? I have looked at http://source.android.com, but there seems to be no solution for windows. I tried to follow the linux instructions from cygwin, but it doesn't seem to work(and i'd prefer to work in windows if possible).
I am still new to android development, so i may be missing something important. Is there anything wrong with this manifest declaration?:
<activity android:name=".Arrowscreen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I will refrain from posting my whole code sample because it is lengthy, but i will tell you that it uses the accelerometer, gps, and a runnable for the main loop on a timer with "postDelayed". the gps fine location permission is in the manifest also. I am stuck, so any help would be much appreciated. Thanks!
edit: the following is the part of my code where i get the runtime exception
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.arrow);
img=(ImageView)findViewById(R.id.ArrowBackground);
arrow1=(ImageView)findViewById(R.id.turningArrow);
GPSx=(TextView)findViewById(R.id.textView1);
GPSy=(TextView)findViewById(R.id.textView2);
MGNTx=(TextView)findViewById(R.id.textView3);
MGNTy=(TextView)findViewById(R.id.textView4);
angle = 0;
lastAngle = 0;
arrowAngle = 0;
mValues[0]=0; mValues[1]=0; mValues[2]=0;
//mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(UpdateArrow);
mHandler.postDelayed(UpdateArrow, 400);
Unless I've misunderstood your question...
In Eclipse, set a breakpoint at the first line of onCreate in your Activity, and launch the app in debug mode (Run -> Degub As -> Android Application).
Two Blog posts on doing this:
1. http://www.droidnova.com/debugging-in-android-using-eclipse,541.html
2. http://www.latenightpc.com/blog/archives/2007/11/21/starting-a-debug-session-for-android-with-adt
Check out ur "Arrowscreen" class extends "Activity" class or not, if not first do that...
I think this may help.
public class Arrowscreen extends Activity{
.....
....
}
in AndroidMainfest.xml
<activity android:name="Arrowscreen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Categories

Resources