i want to start an intent in a service,the intent is used to called somebody.
follow is my code:
Intent call=new Intent("android.intent.action.CLL",Uri.parse("******");
call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(call);
Log.d("test","success");
and the AndroidManifest.xml
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".detimecall"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".gettime" />
</application>
<uses-permission android:name="android.permission.CALL_PHONE"/>
how can i solution this problem?
The first line of your code is incorrect:
Intent call=new Intent(android.intent.ACTION_CALL,Uri.parse("******");
See here for more on intents.
Related
I'm trying to start an activity in another package, I already saw a lot of answers on the topic, but the answers I found don't seem to work for me.
Here how I call the other activity:
Intent intent = new Intent();
intent.setClassName("com.packageroot.package2", "com.packageroot.package2.MainActivity");
context.startActivity(intent);
And here my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.packageroot" >
<application
<activity
android:name=".package1.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.packageroot.package2.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme"
android:parentActivityName=".package1.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".package1.MainActivity"/>
</activity>
And I still get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.packageroot.package2/com.packageroot.package2.MainActivity}; have you declared this activity in your manifest?
What I don't get is that the path indicated is the error is exactly the name of the activity...
Thanks a lot in advance.
You could try adding the package to the build.gradle file under dependencies:
dependencies {
compile 'com.packageroot.package2'
}
change this line:
intent.setClassName("com.packageroot.package2", "com.packageroot.package2.MainActivity");
to
intent.setClassName("com.packageroot", "com.packageroot.package2.MainActivity");
The first parameter is "package name".
http://developer.android.com/reference/android/content/Intent.html#setClassName%28java.lang.String,%20java.lang.String%29
If your intent go through packages,this is what you should do.
In your Manifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true">//got to declare this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="YOUR ACTION NAME" />
//At least one category,use DEFAULT if you don't have one
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And in your Activity
Intent intent = new Intent();
intent.setAction(YOUR ACTION NAME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
Best Solution Work for me is controlling the back Button
#Override
public void onBackPressed() {
Intent intent = new Intent(CurrentActivity.this, SecoundActivity.class);
startActivity(intent);
finish();
}
Good afternoon,
I have an activity that calls another. The code is as follows:
Intent i = new Intent(getApplicationContext(),Menu.class);
startActivity(i);
When I run the application get the following error:
android.content.ActivityNotFoundException: Unable to find explicit activity class {proyecto.uvigo/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
I do not understand what is wrong because I have already stated, the Activity Menu on the AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="proyecto.uvigo"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Inicio"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".Login"></activity>
<activity android:name=".Menu"></activity>
<activity android:name=".RecuperarPass"></activity>
<activity android:name=".Auxiliar"></activity>
<activity android:name=".MiPerfil"></activity>
<activity android:name=".CambiarPass"></activity>
</application>
Thanks!
It's because your code is using android.view.Menu as an Activity instead of your Menu class. Try this:
Intent i = new Intent(getApplicationContext(), proyecto.uvigo.Menu.class);
startActivity(i);
Alternately, you could rename your Menu class to something like UvigoMenu or UvigoMenuActivity in your class and in your manifest, just to avoid confusion like this.
I am not sure but there is something wrong with Unable to find explicit activity class {proyecto.uvigo/android.view.Menu};. Why android.view.Menu?. Please, check if import android.view.Menu class. If yes, use this
Intent i = new Intent(getApplicationContext(), proyecto.uvigo.Menu.class);
or import proyecto.uvigo.Menu instead of android.view.Menu.
start Menu activity as:
Intent i = new Intent(getApplicationContext(), proyecto.uvigo.Menu.class);
startActivity(i);
or
Intent i= new Intent();
i.setComponent(new ComponentName("proyecto.uvigo", "proyecto.uvigo.Menu"));
startActivity(i);
change
<activity android:name=".Menu"></activity>
to
<activity android:name=".Menu">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I am trying to use Implicit intent to launch an activity within the same application and for an activity of another application(my other application, not the native one), but couldn't succeed in any of the cases.
Here is my sample code for the first part (i.e. to launch an activity within the same application):
Inside Activity TESTActivity
Intent intent = new Intent();
intent.setAction("com.myapp.game.myimplicit_action");
startActivity(intent);
and here is my manifest file declaration for some activity say 'ImplicitActivity' with the same action:
<activity
android:name=".TESTActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ImplicitActivity">
<intent-filter>
<action android:name="com.myapp.test.myimplicit_action" />
</intent-filter>
</activity>
Both the activities TESTActivity and ImplicitActivity are in the same application under same package. Still my ImplicitActivity activity is not getting called.
I have figured out the problem. Posting the answer for the others facing the same problem.
We need to add Default Category in order to make Implicit intents work. So here is the correct manifest entry for the same activity :
<activity
android:name=".TESTActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ImplicitActivity">
<intent-filter>
<action android:name="com.myapp.test.myimplicit_action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I keep getting "ActivityNotFoundException: Unable to find explicit activity class ... " when using Eclipse's emulator to call the activity of another application from an application. Perhaps the problem maybe related to I am not able to download to/find both applications at the same time when I click on "Manage Applications" in Settings. This is the first project I need to call the activity of another application. But I am not sure the code is correct either. Please help me determine if there are errors in the code snippets I present below. It is hinted that I can set the action field of the intent to achieve the objective but have not found learning material for this. I learned about using the setComponent method in the calling app and to add android:export to the called activity's AndroidManifest.xml. Thanks in advance!
Calling app's relevant source code:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage", om.MyPackage.Activity1));
startActivity(intent);
Calling app's relevant AndroidManifest.xml :
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity1">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Relevant code of AndroidManifest.xml of the activity of another application
<activity android:name=".Activity1" android:exported = "true">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Firstly point out that you're trying to start Activity in Application2 from Activity in Application1
You have to give them separate namespaces
both applications now have com.MyPackage.* prefix
OR use names Activity1 and Activity2
So you will have
com.MyPackage1.Activity1
// and
com.MyPackage2.Activity1
Then you can use this code, to start Activity1 in MyPackage2 from MyPackage1.
// in file com.MyPackage1.Activity1
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage2", "com.MyPackage2.Activity1"));
startActivity(intent);
And your AndroidManifest.xml files should look like this:
first
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage1.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
second
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage2.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
see related SO question:
How to start activity in another application?
How do I start my app from my other app? (they will not be package together)
--update
Manifest of the second app:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloAndroid"
android:label="#string/app_name">
<intent-filter>
<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"/>
</intent-filter>
</activity>
<activity android:name=".HelloAndroid">
<intent-filter>
<action android:name="com.example.helloandroid.HelloAndroid" />
</intent-filter>
</activity>
</application>
</manifest>
I calling it with:
startActivity(new Intent("com.example.helloandroid.HelloAndroid"));
and it throws:
07-16 15:11:01.455: ERROR/Desktop(610): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }
Ralated:
How to launch android applications from another application
In the first app, you will have to modify the AndroidManifest.xml. Specifically, you are going to add a custom action into the intent-filter of the activity that you want to launch from somewhere:
<activity android:name="FirstApp">
<intent-filter>
<action android:name="com.example.foo.bar.YOUR_ACTION" />
</intent-filter>
</activity>
Then, in your second app you use that action to start the activity:
startActivity(new Intent("com.example.foo.bar.YOUR_ACTION"));
With regards to your comments:
Looks like if I change the default name "android.intent.action.MAIN" I'm not able to run the app from the Eclipse in the Virtual Device
Keep in mind you can have as many actions as you want... for instance:
<activity android:name="FirstApp">
<intent-filter>
<action android:name="com.example.foo.bar.YOUR_ACTION" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
This questions seems similar to one I answered earlier today.
If you just want to start like you started it from the launcher:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName( "PACKAGE NAME", "CLASS" ));
startActivity(intent);