How to change Android app name? - android

I want to change android application name programatically. Is there any API to do this? Thanks.

You cant do it pragmatically.its static.Go to menifest file and add android:label="Your application name" in application tag like below
<application
android:icon="#drawable/ic_launcher"
android:label="Your application name">

You can't change the app name programatically. It is in the manifest. Why do you want to do that anyways?

You could try to change the name using Antscripts, but this could just happen during devTime.
The appname itself does stand in the manifest.xml:
<application android:label="My App name">
Mostly its refered to the R.String file.
Otherwise as codeBegin already said, use setTitle("AppName") to change the title in the current activity.
If you really want to change the name of the WHOLE app, this would NOT be possible, just imagine what a chaos will be created if apps are renamed frequently ;)

Related

Android: how to update app's label dynamically

I want to change the name of the application which is defined in application tag like:
<application android:icon="#drawable/icon" android:label="#string/app_name">
Here the label is defined in resource xml, but what I want to achieve is that user input app_name of his choice and save it and then this new name should be used on Home or Launcher screen of device.
I know there is a way to do by using ActivityAlias but again the label is pre-defined and it's not a dynamic way to do it.
I read some articles that there are some apps like Magisk which changes it's app name & package name through user input.

Change android:label in activity

I'm working in the project that to be a template to many apps.
So far everything is configured via JSON.
But I had a doubt: is It possible to change android:label via JSON?
this should to happen at runtime.
<application
android:allowBackup="true"
android:icon="#drawable/icon"
-> android:label="#string/app_name"
That is not at all possible. It is not possible to modify the value of a string resource from code
But, if you want to change the Title Bar of an activity, you can use
setTitle()
try this
this.setTitle("your title");
This will not change the label of the app

Voice command for apps in Google Glass?

I have an android app developed to run on the google glass. And I run it using the adb. is it possible to give configure a voice command so that I can trigger it by saying "Ok GLASS" + "My Command" ??
Update - After XE16 update the following method does not work, the new solution is here Why is my voice command missing from the ok glass menu in XE16?
What you have to do is,
Inside the manifest file add these tags under the service which you wanted to trigger on your voice command.
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger_start" />
And you have to create a folder called xml inside res and add a xml file named as voice_trigger_start.xml.
Inside that add these lines
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="#string/its_me_amalan" />
Open the values folder inside the res folder and edit strings.xml, so it will look like this
<resources>
<string name="app_name">Amalan</string>
<string name="its_me_amalan">Hello Amalan</string>
<string name="stop">Stop</string>
</resources>
Now install the app onto Glass and say "ok glass, Hello Amalan" and the app opens.
Reference: http://pathofacoder.com/2013/11/20/google-glass-adding-your-own-voice-commands-to-your-apps/
Yesterday, Google released the XE12 firmware update, which put us into trouble with all custom launchers. Both Launcher2.apk and Launchy stopped working for me so as a workaround I implemented a method which is also a good answer to your question. Take a look at this page http://divingintoglass.blogspot.com/
I did this for a Glassware app developed with the GDK in this commit:
https://github.com/luisdelarosa/HelloGlass/commit/c5038ed2ff019306becb32211354358833b6fafc
Here is what is in that commit step-by-step:
Modify the AndroidManifest.xml to add a VoiceTrigger intent, inside either the Activity or the Service you want to launch via voice. Note that you can also optionally delete the Launcher intent since Glass does not use those like traditional Android.
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/glass_voice_trigger" />
Add the VoiceTrigger XML that the VoiceTrigger intent references, which should contain the string that you want the user to activate your app. In this case, we're calling it res/xml/glass_voice_trigger.xml
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="#string/glass_voice_trigger"/>
Optionally, put the string in the previous step into a strings.xml file. (You could have also just hardcoded that string into the VoiceTrigger XML as the value of the keyword attribute of the trigger node.) In this case, it is at res/values/strings.xml and our trigger is "say hello". Replace this string with whatever you want the user to say to launch your app.
<string name="glass_voice_trigger">say hello</string>
Don't forget to use permission since XE16 :
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />

How to register a new activity in AndroidManifest.xml?

I always get an error when I run my created application and based on my research I haven't registered my Activity in the manifest. How can I register a new activity in AndroidManifest.xml?
Assuming you're using Eclipse,
Goto your Android Manifest, goto the Applications Tab (at the bottom), click on "Add", Choose Activity. On the right, next to Name: Click on Browse, to get a list of available activities, just add it and you're set! :)
You could right way just edit the Manifest XML aswell. It's upto you.
<activity android:name="com.kl.android.ReadSMS.ViewSMS" />
just use the class name after '.'
like the following
<activity android:name=".ViewSMS"/>
In Android Studio, Go to AndroidManifest.xml file and use
<activity android:name="YourPackageName.ClassName">
For example,
<activity android:name="com.android.favoritetoys.MainActivity">
For More List of activity attributes in AndroidManifest.xml

Android widget in emulator

I have an existing android app.
I added a simple widget to it using the following:
updated my manifest with a <receiver> block which provides information about my AppWidgetProvider implementation
added a new xml files in res/xml with a <appwidget-provider> element that contains the height/width/updatePeriod/initialLayout/icon/label attributes
added a simple default layout with an ImageView and a TextView
implemented my AppWidgetProvider
When I build and deploy this to the emulator my Widget doesn't show up in the list of widgets. Am I missing some step to 'install' the widget? Do I need to do anything special to make it appear in the emulator?
EDIT:
Here's what my manifest receiver looks like:
<receiver android:name=".MyAppWidgetProvider"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/my_appwidget_info" />
</receiver>
and here's what my my_appwidget_info.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="#drawable/ic_logo"
android:label="MySampleApp"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="86400000"
android:initialLayout="#layout/my_app_widget" >
</appwidget-provider>
Does your receiver tag in the manifest have the proper intent-filter and meta-data? It should look like the example in the documentation:
<receiver android:name="MyAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/my_appwidget_info" />
</receiver>
The receiver needs both of those pieces to be recognized as an app widget.
Edit: The <receiver> tags also need to be located inside the <application> tags.
If your app is installed on the SD card, all your widgets will quietly refuse to show up in the list. (The docs do make it clear that you can't have widgets if you're on the external storage).
You can go to the settings in the home screen, go to Applications, and go to your app. If it offers you to "Move to phone", then it is on the SD card. You can set the install location to internalOnly to prevent it from going onto the SD card.
If you do allow installation on SD card (because users will typically ask for that), they need to be clear that they can't have the widget in that case. If an app is on SD card and you want to use the widget, you first have to move the app back to internal storage and then reset the phone (!).
I had the same issue as well. A few things to check that can stop it from showing up on different models.
1)Must have a minHeight and minWidth set on AppWidget-Provider in the xml, if you remove either of those and launch in emulator, your widget will be gone.
2)Some models have issues if you don't supply a previewImage in the AppWidget-Provider
3)Some models can have issues if you install on the SD Card rather than internally, although I still prefer to install on SD Card.
4)Some models need to have an Activity with Main and Launcher defined even if you don't intend on using any Activities. (You can simply make a dummy one that says 'this is a widget app only'
5)You have to have your manifest setup correctly as shown in TinJa's answer.
I fought through this for quite a while before finally getting it to show up in all models and emulators, so be patient, make sure you aren't missing anything and set the values that need to be there. Remember some phones cache the Widget List and may not update until you have launched your first Activity or Rebooted the phone.
Hope that helps.
Sam
I had the same problem then I finally figure it out. Usually when you emulate an application, it has an activity to load. For a widget-only app, that isn't the case, but the IDE still thinks you're trying to launch an activity.
To change this go to your Build Options
then change the Launch Options to Nothing
I had the same problem. It turned out I accidentally had two meta-data resource xml files in two different folders, my "layout" folder and my "xml" folder. It was finding the (empty) resource in "layout" first, and using that for its meta-data.
It was a stupid mistake, but make sure you have only one xml file of that name that's pointed to in your receiver meta-data tag. Also I think it should always be in the xml folder.
I had the same problem.
And my problem was that I have /layout/main.xml file when I delete it the widget appear!
It sound like #ubzack answer but I think he talk about something else [same xml file name]

Categories

Resources