Launching Intent cannot find Activity - java

My program has a list of tabs that each contain a list of people. Clicking a person should edit their details, but instead, clicking a person throws an ActivityNotFoundException. My code that starts the edit activity:
Intent intent = new Intent("my.package.EDIT"); // Person is both
intent.putExtra("my.package.PERSON", (Parcelable) myPerson); // Parcelable and
GroupArrayAdapter.this.getContext().startActivity(intent); // Serializable
Relevant part of AndroidManifest.xml:
<activity android:name="EditActivity">
<intent-filter>
<action android:name="my.package.EDIT" />
</intent-filter>
</activity>
What's going on?

There's two ways to start an Activity, either explicitly or implicitly. Explicitly means that you use the class name directly; usually if you're calling an Activity that is within your own application, what you mean to use is the explicit method because it's far easier:
Intent intent = new Intent(context, EditActivity.class);
context.startActivity(intent);
However, if you really do mean to use implicit filtering, then your intent filter is missing something. Every implicit intent filter requires the category android.intent.category.DEFAULT (with few exceptions). Try this and see if it works:
<activity android:name="EditActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="my.package.EDIT" />
</intent-filter>
</activity>
Suggested reading: intent filters.

When you instantiate your Adapter, pass the context from the calling activity. Then in your adapter use context.startActivity(...);

Related

No Activity found to handle Intent for Default Activity

I get error No Activity found to handle Intent when I try to start Default Activity from another Activity using
Intent start = new Intent("com.name.name.MainActivity");
startActivity(start);
finish();
I guess this is because in AndroidManifest for Default Activity I have android.intent.action.MAIN
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Is there a way to start Default Activity from another Activity when Default Activity is finished before?
You are trying to start the activity using the action name..
Note:startActivity() always adds CATEGORY_DEFAULT to an Intent if there is no other category specified(Here you have no category specified in your internt so its default).
Hence, an <intent-filter> for an <activity> always needs a <category>, whether DEFAULT or something else (here it needs default that's why error says No Activity found to handle Intent for Default Activity)
The LAUNCHER category says that this entry point should be listed in the application launcher.
The DEFAULT category is required for the Context.startActivity() method to resolve your activity when its component name is not explicitly specified.
Try to specify two intent filters:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.name.name.MainActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Then you can start the activity using the action name:
Intent intent = new Intent("com.name.name.MainActivity");
startActivity(intent);
or simply you can go with the class name:
Intent intent = new Intent(context, MainActivity.class);
startActivity(intent);
Intent i = new Intent(otheractivity.this, MainActivity.class);
startActivity(i);

Unable to find explicit activity class Android

Ugh, so many posts on StackOverflow similar to my problem but none fix it :/
I am currently learning android development. In my main activity I do:
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.changeName:
Intent intent = new Intent(this, PreferenceActivity.class);
startActivityForResult(intent, 1);
return true;
}
return false;
}
Preference.java is a freshly created activity with nothing in it except the automatically created onCreate method. The error is:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.package.chat.oneway.client/android.preference.PreferenceActivity}; have you declared this activity in your AndroidManifest.xml?
My android manifest has:
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".ChatClient"
android:label="#string/app_name" />
<activity android:name=".Parent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PreferenceActivity"></activity>
</application>
As you can see, .PreferenceActivity is in the manifest. The packages for the ChatClient and PreferenceActivity activities are the same com.package.chat.oneway.client package.It's been driving me nuts for the past 4 hours.
As you can see, .PreferenceActivity is in the manifest.
Yes, it is. However, that is not what your Intent is using. If you look more closely at the error message, you will see that your Intent is using android.preference.PreferenceActivity.
This comes when you reuse existing class names. There are countless possible class names. Rename yours to something else, and you can avoid this sort of problem in the future.
Or, if you are completely set on having your class named PreferenceActivity, then remove the import android.preference.PreferenceActivity statement from the class where you are creating your Intent. Or, change your Intent to:
Intent intent = new Intent(this, com.package.chat.oneway.client.PreferenceActivity.class);

Android Manifest Confusion

I noticed that there are two ways to start an Activity with Intent.
1) Using - [android:name=".MainActivity"]
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
2) Using - [action android:name="com.example.MainActivity"] from the Intent_Filter
String actionName = "com.example.MainActivity";
Intent intent = new Intent();
intent.setAction(CUSTOM_ACTION);
context.startActivity(i);
So what's the difference? Why do we have to set both the name and the intent_filter in the manifest if they both do the same thing?
===---==
Second confusion I have is... Is there a way to use the "OK Google" voice-launch option to launch an Activity that's NOT shown in the app list? Basically actual App Launcher launches the "default homepage" of the app, whereas voice launch takes you to a specific Activity directly?
I suspect some combo of these might get it done:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
If your class is in your main package, you can use this way:
.YourClass
or
com.example.YourClass
If your class isn't in your main package, you should use this way:
packagename.YourClass

How can I get a number placed in a text message on Android?

I want to add a feature to my app that when I touch the number in a message, the user can decide to send the number to my app or Android Dialer.
For example my friend send me a code and i want to use this code for special ussd code that my app run it.
I think I have to use implicit intent but I don't know how?
Thanks
I have quoted the below links
-intent filter
-Intents implicit\explicit
Implicit intents specify the action which should be performed and
optionally data which provides data for the action.
For example the following tells the Android system to view a webpage.
All installed web browsers should be registered to the corresponding
intent data via an intent filter.
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.vogella.com")); startActivity(i);
If an Explicit intent is send to the Android system, it searches for all
components which are registered for the specific action and the
fitting data type.
If only one component is found, Android starts this component
directly. If several components are identifier by the Android system,
the user will get an selection dialog and can decide which component
should be used for the intent.
How to use
You can register your own components via Intent filters. If a
component does not define one, it can only be called by explicit
intent.
Register an activity as Browser
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
UPDATES
A code sample for mimeType
<activity android:name="ShareActivity">
<intent-filter>
<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>
I assume you are talking about a number in a SMS that you received. On clicking that number you want the user to get an option to either dial or use your app.
If yes then you need to include intent filter in your manifest file for launcher activity.

Reading value of android:scheme programmatically

I want to know if it is possible to read the value of android:scheme from the Android-manifest-file (example below) programmatically.
<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:scheme="zxtest" />
</intent-filter>
You should be able to get this information from the PackageManager:
PackageManager pm = getPackageManager();
ActivityInfo activityInfo = pm.getActivityInfo(component,
PackageManager.GET_INTENT_FILTERS);
Unfortunately, however, you can't :-( This call SHOULD return the intent filters (according to the documentation), but it seems that the Android developers haven't gotten around to actually implementing it yet :-(
See Unable to get intent filters from a package
I'm assuming you mean that the intent has been called and you're trying to find the scheme from your activity's code?
In your activity's onCreate method, you can do the following:
Intent intent = getIntent();
Uri data = intent.getData();
String scheme = data.getScheme(); // "zxtest"

Categories

Resources