no activity found to handle - android

I am getting error while click on list item
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String selected =((TextView)view.findViewById(R.id.no)).getText().toString();
Toast toast=Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT);
toast.show();
try {
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse(selected));
startActivity(in);
} catch (SecurityException e) {
Log.e("PERMISSION_EXCEPTION","PERMISSION_NOT_GRANTED");
}
}
An error is Message which i am getting in Logcat
01-06 10:37:19.091 19537-19537/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sairamkrishna.myapplication, PID: 19537
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=1234 567 89 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1856)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1552)
*Manifest file here i have added permission and MainActivity and intent filter
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

You are getting
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.CALL dat=1234 567 89 }
All activities must be declared in the AndroidManifest.xml. Without the declaration, ActivityNotFoundException is thrown.
Make sure activity is added in AndroidManifest & Intent.ACTION_CALL calling properly .
You can share your manifest .
Did you add this ?
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

You can try (your selected text must be format: tel:xxxxxxxxx)
Intent in = new Intent(Intent.ACTION_DIAL,Uri.parse(selected));
startActivity(in);
Remember add this permission:
<uses-permission android:name="android.permission.CALL_PHONE" />

First of all since you are using implicit intent , you do not need to specify call permission in manifest.
Whenever you are calling any implicit intent if it doesn't find any matching activity which can perform given action , then this exception occurs.
You can handle that by using following code.
Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse(selected));
List<ResolveInfo> list=new PackageManager().queryIntentActivities(intent ,0);
if(list.size()>0){
Intent chooser = Intent.createChooser(intent, "title");
startActivity(chooser);
}else{
//Show toast or alert saying no activities available to perform specified action.
}

Important thing is to make Phone Call data format is like this tel:your_number :)
Intent in=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+selected));

Related

android studio intent inside intent crash

So I have two activities, let's call them A and B, activity A have a text input and a button, which call to activity B with an intent method:
and I have activity B which have also intent to the camera application:
ImageView photo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
TextView textView = findViewById(R.id.textView);
Button buttonCapture = findViewById(R.id.buttonCapture);
photo = findViewById(R.id.photo);
buttonCapture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent1, 0);
}
});
}
#TargetApi(Build.VERSION_CODES.KITKAT)
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap) (data != null ? requireNonNull(data.getExtras()).get("data") : null);
photo.setImageBitmap(bitmap);
}
and when I launch this in a simulator, I get the first A activity fine, click on the button, it open activity B, I press the button again, and it returns me to activity A or crash(random?)
my manifest file:
package="com.example.user.app">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".A">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".B">
</activity>
</application>
with the exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.app, PID: 18441
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.android.camera2/com.android.camera.CaptureActivity } from ProcessRecord{296747c 18441:com.example.user.app/u0a88} (pid=18441, uid=10088) with revoked permission android.permission.CAMERA
ok, I see...
Starting Android 6 (API 23), if your app has CAMERA permission declared in the manifest, it needs that CAMERA permission to be GRANTED in order to access ACTION_IMAGE_CAPTURE etc... too (which normally do not require the CAMERA permission on their own). If not, then it automatically raises a SecurityException.
do like below!!!
1- If you only need ACTION_IMAGE_CAPTURE etc..
Remove the CAMERA permission from manifest and you would be fine
2- If you need CAMERA permission too
Check for CAMERA permission at runtime and only start the intent when the permission is available
1) it maybe happens when you don't declare your B activity in manifests!!!
2)remove final before defining EditText and try again!!!
if you send your logs, I can help you better...

how to start an activity in another module explicitly

I created an aar and i added it to my project as an module. in this module i have a HelloWorldActivity that i want to run.
my module manifest looks like this.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="ir.sibvas.testlibary1.HelloWorldActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="ir.sibvas.testlibary1.HelloWorldActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Now i can start this activity from my project using this code
Intent intent = new Intent("ir.sibvas.testlibary1.HelloWorldActivity");
startActivity(intent);
but as you can see this code is implicit and problem with implicit calling is that if i use this module in more than one app, both installed on user device it will show an app chooser dialog to user. So how can make this call explicit, preventing user from switching app?
this code will not run since HelloWorldActivity is not in the same package as calling activity
Intent intent = new Intent(this, HelloWorldActivity.class);
startActivity(intent);
I really don't want to change my module for each project that uses it.
You can use the Class.forName(), it worked for me when i was needed to start activity which is in another module in my project.
Intent intent = null;
try {
intent = new Intent(this,
Class.forName("ir.sibvas.testlibary1.HelloWorldActivity"));
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
First module activity launch then second module activity launch
and write a line of code is perfectly fine.
try {
Intent launchIntent =
getPackageManager().getLaunchIntentForPackage("com.your.packagename");
if (launchIntent != null) {
startActivity(
launchIntent); //null pointer check in case package name was not found ClassNotFoundException
}
} catch (e) {
e.printStackTrace();
}
Intent intent = new Intent();
intent.setClassName(context.getPackageName(), "ir.sibvas.testlibary1.HelloWorldActivity");
startActivity(intent);

how to set Activity Title in Intent?

In TabHost we can do getActionBar().setTitle("ACTITIVTY TITLE").
But what about in the intent?
Is there possible way to set title in intent?
code
Intent i = new Intent(MenuActivity.this, DrawerListActivity.class);
startActivity(i);
Toast.makeText(getBaseContext(), "RF number: " +
KEY_RFnumber, Toast.LENGTH_SHORT).show();
MainActivity.class
public void send(View view) {
Intent intent = new Intent(this, DrawerListActivity.class);
String message = "Drawer Title";
intent.putExtra("key", message);
startActivity(intent);
}
DrawerListActivity.class, in onCreate()
String message = getIntent().getStringExtra("key").toString(); // Now, message has Drawer title
setTitle(message);
Now, set this message as Title.
You can't set the title directly with the intent. You could pass along the title in the intent, and have your target activity extract the title from the intent and set it. This would only be a few lines of extra code in the target activity.
I got it! I just declare from my MainActivity a public static String that holds a string which I set in my Intent, then it call to my DrawerListActivity. It works perfectly! Thanks.
i just paste another person answer regarding this question may be it will help you
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name_full" >
//This is my custom title name on activity. <- The question is about this one.
<intent-filter android:label="#string/app_launcher_name" > //This is my custom Icon title name (launcher name that you see in android apps/homescreen)
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Starting the Main activity from another activity

I am trying to achieve following case on Android, but no success:
1) Launch Application (Launcher Activity which is a subclass of Base Activity). The Base Activity has code as follows:
///This is in BaseActivity
#Override
public void onCreate(Bundle instance)
{
super.onCreate(instance);
//Config.isLoggedIn() is a static function.
if(! Config.isLoggedIn())
{
////Config.startLoginActivity is a static function
Config.startLoginActivity(this, getIntent());
finish();
}
}
The Config.startLoginActivity functions is defined as
public static void startLoginActivity(final Context ctx, final Intent finishIntent)
{
Intent i = new Intent(ctx, ItemListActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("FINISH_INTENT", finishIntent);
ctx.startActivity(i);
}
Now, the ItemListActivity contains a list of Items as {Item1, Item2, Item3}. In ItemListActivity, I am saving the passed "finishIntent" as
///This is ItemListActivity onCreate Method
if(getIntent().hasExtra("FINISH_INTENT"))
mFinishIntent = getIntent().getParcelableExtra("FINISH_INTENT");
and the onItemListSelected method is described as follows :
#Override
public void onItemSelected(String id) {
Config.setLogInState(true);
if(mFinishIntent != null)
{
Log.i("ITEMLISTACTIVITY", "Class Name = " + mFinishIntent.getClass().getName());
Log.i("ITEMLISTACTIVITY", "Starting mFinishIntent Activity");
startActivity(mFinishIntent);
finish();
}
}
But the issue is the Main Activity is not being launched again, Android takes me to the home screen instead. While looking for a solution, I saw that Google I/O app has the same implementation and that works flawlessly but in my case it is not. I am unable to figure it out. Please help.
Thanks in Advance.
Manifest File is as follows :
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.app.myapplication.ItemListActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.app.myapplication.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>
Ok Here is a quick help which works for 100 percent which I'm using not mostly but EVERYTIME! you must past it through intent and in your case here it is how it must look like.
Intent intent = new intent(//name of your activity in which you are at the moment.this, //name of activity to which you want to go.class);
startActivity(intent);
Hope this will help

[Android]BroadcastReceiver(Action_headset_plug) not firing

I declared a BroadcsastReceiver(Action_headset_plug) in AndroidManifest.xml and defined a BroadcastHandler.class implement BroadcsastReceiver . I run the apk on the device and the receiver doesn't fire. However , it work correctly when I use registerReceiver() in the Activity. Do I miss something in the AndroidManifest.xml?
This is the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="irdc.Earphone_test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.ACTION_HEADSET_PLUG"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:enabled="true" android:name="BroadcastHandler">
<intent-filter>
<action android:name="android.intent.ACTION_HEADSET_PLUG"></action>
</intent-filter>
</receiver>
<activity android:name=".Earphone_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>
</application>
</manifest>
This is the receiver code
public class BroadcastHandler extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)){
String mes;
int state = intent.getIntExtra("state", 4);
if(state == 0){
mes ="out";
}else if(state == 1){
mes ="in";
}else {
mes ="others";
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Headset broadcast");
builder.setMessage(mes);
builder.setPositiveButton("Okey-dokey", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}
}
For listening to headset changes, the broadcast receiver cannot be declared in the manifest, it must be dynamically registered. Not all receivers work when declared in the manifest and this is an example where you need to register it programmatically.
You can call this for example in an Activity's onResume method or in a Service's onCreate method:
headsetReceiver = new BroadcastHandler();
registerReceiver(headsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
Then in the Activity's onPause method or in the Service's onDestroy method you need to unregister the receiver:
unregisterReceiver(headsetReceiver);
The name is wrong in the manifest entry. Use the full package name, or start it with a period if you want it implicitly appended to the app's package name:
<receiver android:enabled="true" android:name=".BroadcastHandler">
Most examples of receivers do not start an AlertDialog but Toast a message or create a Notification in Status bar. I am sure that you cannot start an Activity because the "content" object stops existing but not if you can built an AlertDialog. (documentation of Broadcasts)
So you can try at your receiver a Toast message to make sure that it works.
Example with Notification: http://www.anddev.org/recognize-react_on_incoming_sms-t295.html

Categories

Resources