android.content.ActivityNotFoundException: No Activity found to handle Intent - java

please help , when i run the app, the app launch a Fatal Error im learning
just i create a instat with a call but not run, (sorry for my english)
.......................................................................
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.octa.appprueba3">
<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" />
<category android:name="android.intent.category.APP_CONTACTS" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>
</manifest>
my code:
public class SecondActivity extends AppCompatActivity {
private EditText editPhoneText;
private ImageButton imageCallButton;
private final int PHONE_CALL_CODE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
editPhoneText = (EditText) findViewById(R.id.editTextPhone);
imageCallButton = (ImageButton) findViewById(R.id.imageCallButton1);
imageCallButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
implicito();
}
});
}
public void implicito(){
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("Tel: 9999999" ));
startActivity(intent);
}
}

You may want to check whether your device can handle your intent by doing this:
PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Cannot handle this intent");
}
What's more, if you are placing a call like so, there is NO need to declare the permission in your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Because you are not directly calling someone within your app. You are actually transferring the "duty" to other apps which can handle your intent to call. This doesn't need a permission.
To directly make a call within your app, the intent should be Intent.ACTION_CALL, which needs the permission you declared.
Hope this will help.

There is no activity on your device that handles ACTION_DIAL for a Tel: scheme. Try:
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9999999" ));
Case and whitespace are important when assembling a Uri.
Also note that even my revised Intent will not work on all devices, such as on an Android tablet that lacks a dialer.

Related

Confused about the process of sending a broadcast -- android beginner

I'm trying to send a simply customized broadcast by clicking a button, and the receiver will push a toast as it receives the broadcast. But as I clicked the button, nothing toasted with an error message in the logcat:
2021-01-18 16:23:18.870 480-480/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2021-01-18 16:23:20.931 485-485/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2021-01-18 16:23:20.931 485-485/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
The MainActivity is:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.broadcasttest2.MY_BROADCAST");
sendBroadcast(intent);
}
});
}
And the BroadcastReceiver is:
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Toast.makeText(context, "My Broadcast Received", Toast.LENGTH_SHORT).show();
throw new UnsupportedOperationException("Not yet implemented");
}
}
I have also registered the action inside the BroadcastReceiver:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcasttest2">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.BroadcastTest2"
>
<receiver
android:name=".MyBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.broadcasttest2.MY_BROADCAST" />
</intent-filter>
</receiver>
<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>
Could anyone help me with that? Many thanks!
for in app broadcast communication you have to register the broadcast receiver in the Activity, in your case you missing an syntax inside onCreate like this one:
BroadcastReceiver myReceiver = new MyBroadcastReceiver();
registerReceiver(myReceiver, new IntentFilter('com.example.broadcasttest2.MY_BROADCAST'));
for more reference - Broadcast Receiver class and registerReceiver method

scheduling alarmmanager not working on reboot my phone

It's toasting until I didn't restart my phone but after restarting broadcastreceiver2 doesn't receive and nothing happens.
I followed http://stacktips.com/tutorials/android/how-to-start-an-application-at-device-bootup-in-android and many other but nothing happens.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.k2.alarmmanagerdemo">
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.k2.alarmmanagerdemo.MyBroadcastReceiver"
android:enabled="true">
</receiver>
<receiver android:name="com.k2.alarmmanagerdemo.BroadCastRecevier2"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startAlert();
}
});
}
public void startAlert() {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),
1000 * 5,pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",Toast.LENGTH_LONG).show();
}
}
MyBroadcastReceiver.java
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm...." + System.currentTimeMillis(), Toast.LENGTH_SHORT).show();
Log.i("Alarm.", "alarm called" + System.currentTimeMillis());
}
}
BroadCastRecevier2.java
public class BroadCastRecevier2 extends BroadcastReceiver {
MainActivity activity = new MainActivity();
#Override
public void onReceive(Context context, Intent intent) {
activity.startAlert();
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent i = new Intent();
i.setClassName("com.k2.alarmmanagerdemo",
"com.k2.alarmmanagerdemo.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Toast.makeText(context, "BOOT", Toast.LENGTH_SHORT).show();
Log.i("myboot","boot compleated inside");
}
}
}
Remove this line from your <receiver> declaration for BroadcastReceiver2:
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
That line in the <receiver> tag is telling the system that only packages which have this permission are allowed to send your class the Intent. Its' likely confusing the system and preventing the Intent from being sent to your receiver.
You may also find this article helpful when learning about alarms and the boot complete receiver.

LocalBroadcastManager didn't receive messages

My LocalBroadcastManager callback function dosen' receive messeges. Can someone tell my why?
I try to do it on my Samsung Galaxy S3 mini (4.1.2 -Jelly Bean, API 16).
SenderClass:
public static final String BROADCAST = "com.android.SOME_BROADCAST";
private Context context;
public SenderClass(Context context) {
this.context = context;
//...
Intent intent = new Intent(BROADCAST);
//intent.putExtra(EXTRA_SOMEEXTRA, "some extra");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
//just to keep it simple i do it here
}
MainActivity
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive"); //this is never called!
}
};
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
LocalBroadcastManager.getInstance(this).registerReceiver(
broadcastReceiver,
new IntentFilter(SenderClass.BROADCAST)
);
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}
edit: here the manifest
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android....">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".Services.MyService"
android:enabled="true"
android:exported="false"></service>
</application>
</manifest>
Try this step:-
Register your broadcast in onCreate and Unregister broadcast in onDestroy of Activity.
Thanks,
It may helpful for you.

startActivity(intent) is not opening activity

I'm making an android app with 2 activities and a Java class that reads/writes RFID data using NFC.
I'm using the enableReaderMode() method to enable reader/writer mode in the mainActivity, which then calls onTagDiscovered in a separate java class. Once in the onTagDiscovered method, I'm calling mainActivity.startNewActivity() to open a the second activity. I know that I'm reaching startNewActivity() because of a log message, but the activity is not actually starting. The app doesn't crash, and I'm not getting any errors, it just isn't starting. I've tried placing a button in the mainActivity and opening that way, and it works fine. It just doesn't work when I call the method from encode.java.
**I know that it is not necessary to open the activity from Encode.java, and that I could directly code this into MainActivity, but I'm preparing to do something more complex where I will need to open from Encode.java, and I want to test that the activity will open at all.
Here's the code
Encode.java
public class Encode implements NfcAdapter.ReaderCallback {
MainActivity mainActivity = new MainActivity();
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New tag discovered");
mainActivity.startNewActivity();
}
MainActivity
public void startNewActivity() {
Log.v(TAG, "in startNewActivity");
Intent intent = new Intent(this, Success.class);
startActivity(intent);
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/xband"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech" />
</activity>
<activity android:name=".Success" >
</activity>
</application>
</manifest>
Success.java
package com.project;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Success extends Activity {
private static final String TAG = "encode";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.success_activity);
Log.v(TAG, "in success activity");
}
}
I tried adding the following code and then got this error message:
Encode.java
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New Tag Discovered");
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
mainActivity.startNewActivity();
}
});
}
02-20 11:52:27.739 22088-22088/com.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.project, PID: 22088
java.lang.NullPointerException
at android.app.Activity.startActivityForResult(Activity.java:3474)
at android.app.Activity.startActivityForResult(Activity.java:3435)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:3677)
at android.app.Activity.startActivity(Activity.java:3645)
at com.project.MainActivity.startNewActivity(MainActivity.java:110)
at com.project.encoding.Encode$1.run(Encode.java:331)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Someone at work was able to help me figure this out.
This wasn't working because I was creating a new instance of the MainActivity in Encode, instead of referencing the existing MainActivity.
In MainActivity we added:
private static MainActivity _instance = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
encode = new Encode();
enableReaderMode();
MainActivity._instance = this;
}
public static MainActivity getInstance() {
return _instance;
}
and in Encode we called the startNewActivity method by calling:
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New Tag Discovered");
MainActivity.getInstance().startNewActivity();
});
so that now Encode is using the existing instance of MainActivity
Instead of:
Intent intent = new Intent(this, Success.class);
Try: Intent intent = new Intent(getApplicationContext(), Success.class);
That worked for me one time cause it "Return the context of the single, global Application object of the current process. "

how to start new activity in android

I want to start a new activity called Counter when a button is clicked, but I got an error that is the activity is not found...so where is the wrong in my code:
t = new Thread(){
public void run(){
try{
sleep(5000);
}
catch (InterruptedException e){
e.printStackTrace();
}
finally{
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
}
}
};
test.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
t.run();
}
});
this is the manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test.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="com.example.test.Counter"
android:label="#string/title_activity_counter" >
</activity>
</application>
</manifest>
Intent intent = new Intent(MyActivity.this, OtherActivity.class);
startActivity(intent);
Change this
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
This is called implicit intent and it needs intent filter
to
Intent counter = new Intent(MainActivity.this,Counter.class);
startActivity(counter);
This is called explicit intent and there is no need for intent filter
You should use explicit intent coz you have
<activity
android:name="com.example.test.Counter"
android:label="#string/title_activity_counter" >
</activity>
Quoting docs
Explicit intents specify the component to start by name (the
fully-qualified class name). You'll typically use an explicit intent
to start a component in your own app, because you know the class name
of the activity or service you want to start. For example, start a new
activity in response to a user action or start a service to download a
file in the background.
Note: An explicit intent is always delivered to its target, regardless of any intent filters the component declares.
Edit:
You should call start() on the thread not run
You can replace this
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
with this, it would work ..
Intent counter = new Intent(MainActivity.this, Counter.class);
startActivity(counter);
Or to let your code work, you are missing intent-filter
<activity
android:name="com.example.test.Counter"
android:label="#string/title_activity_counter" >
<intent-filter>
<action android:name="android.intent.action.COUNTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You should always provide an intent-filer if you want to start an activity with your way ..
you should have t.start();. That is the function that starts a thread.
You may also want to try running on the UI thread by replacing the contents of your finally block with this:
MyActivity.this.runOnUiThread(new Runnable() {
public void run() {
Intent counter = new Intent(MyActivity.this, Counter.class);
MyActivity.this.startActivity(counter);
}
};
And as others have said, use t.start() instead of t.run() as run() will block any further action until it completes.

Categories

Resources