Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you define an Android intent-filter using a string resource?

I wanted to define the string name of my intent in the strings.xml file, and then bind that string to an intent filter, as so:

<intent-filter >
    <action android:name="@string/app_intent" >
    </action>

    <category android:name="android.intent.category.DEFAULT" >
    </category>
</intent-filter>

When i tried this however, i get various errors about the system could find no activity to handle my intent. I was trying to keep values (ie, the intent names) centralized instead of hard-coded in the manifest as well as in code. As it is, at least this lets me centralize it out of the application code, but i still have it hard-coded in the manifest.

Is this really impossible to do or is there some way to make it work?

like image 440
eidylon Avatar asked Dec 09 '11 04:12

eidylon


People also ask

Which component can you specify in an intent filter?

The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond.

What is intent filter and how we can define it?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.

What is string resource in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

Why should you use string resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).


1 Answers

Its not the issue with intent-filter, the issue is with android:name. android:name attribute is not taking string resource for activity name also. example <activity android:name="@string/app" android:label="@string/app_name"> is not valid in android.

like image 50
Sunil Kumar Sahoo Avatar answered Sep 30 '22 03:09

Sunil Kumar Sahoo