No Activity found to handle Intent for Default Activity - java

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);

Related

make an android app in which the launch icon is working as a link

I was wondering if it is possible to make an android app and when the user hits the launch icon, the browser opens with a specific URL. I know that you can make shortcuts on your phone home screen with the URL you want but I was wondering if it is possible as an android app. So the app should don almost nothing just when i tap on it the browser should open..
is this possible? and is yes how should I think it?
Do this in the main activity's onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://stackoverflow.com"));
startActivity(intent);
finish();
}
in the manifest add noDisplay theme:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme = "#android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

Run ContactsSyncAdapterService from outside Android app

If an app has an exported service in the android manifest that means I can run that service from within another app right? For example the service looks like this in the manifest file.
<service
android:name=".account.contactsync.ContactsSyncAdapterService"
android:exported="true"
android:process=":contacts" >
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/sync_contacts" />
<meta-data
android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="#xml/contacts" />
</service>
As you can see the service is set to android:exported="true" which means I should be able to run it from outside of the app right? How do I do that
I tried this and it didn't work
final Intent intent = new Intent();
ComponentName cName = new ComponentName
("com.myapp","com.myapp.ContactsSyncAdapterService");
intent.setComponent(cName);
startActivity(intent);
You're missing an .account.contactsync in your component name:
ComponentName cName = new ComponentName("com.myapp",
"com.myapp.account.contactsync.ContactsSyncAdapterService");
And you'd need to use startService() instead of startActivity() - startActivity() only starts activities.

how to make our activity page open from another application?

I am new in android development, I want to build a music player but the problem in front of me is how do i make my app open from gallery.
For example,
if we want to open any music file then we select it, the the android mobile ask which player do we want to use.
so how can I add my app in that option.
please help.
If you want your app to be in the list for opening an audio file, you need to tell the system your app can open those files. You can do that by adding something like the following to your activity tag in your AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
<data android:mimeType="application/itunes"/>
</intent-filter>
Intent filters are part of the core principles in Android development. You should try to get some knowledge on these basic topics before getting started.
It helps you
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Actually you can open activity not app at self just simply add action intent filter in mainfest like this
<activity class=".foo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="com.me.love" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
other app code :
Intent intent = new Intent("com.me.love");
startActivity(intent);
however if you want to tell android system that your activity can handle some actions like share or send data you just have to add "send" action to your activity in mainfest like so :
<activity class=".boo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
so now when ever user click share button android system will check all activitys that have action string "android.intent.action.SEND" then give the user list of activitys that have send action and if you did added same action as boo activity dose to your activity then it will be one of chooses in the list.

Launching Intent cannot find Activity

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(...);

Categories

Resources