Device disconnects after a call - android

I'm trying to write a simple broadcast receiver that captures voice calls. Below is my receiver class and manifest file. Every time I try to run it, my virtual device gets disconnected right after a call. What am I doing wrong???
package com.example.example06;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class MyPhoneReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "A phone call was received!", Toast.LENGTH_LONG).show();
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example06"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name="MyPhoneReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>
</application>
</manifest>

Maybe change manifest to :
<receiver
android:name="com.example.android.blah.MyPhoneReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>

Related

BroadcastReceiver java.lang.ClassNotFoundException

I try to show a simple toast message on phone startup.
I wasted almost a day trying to figure out why my code did not work.
Here is the full error:
Unable to instantiate receiver com.debug.receivebootcomplete.debug.BroadcastReceiverClass: java.lang.ClassNotFoundException: com.debug.receivebootcomplete.debug.BroadcastReceiverClass
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.debug.receivebootcomplete.debug">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name">
<receiver android:name=".BroadcastReceiverClass" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
And my class:
namespace Debug
{
class BroadcastReceiverClass:BroadcastReceiver
{
public override void OnReceive (Context context, Intent intent)
{
Toast.MakeText (context,"Work",ToastLength.Short).Show ();
}
}
}
In emulator debug the application throw the java.lang.ClassNotFoundException and on phone when reboot the application crash.
Thank you in advance!
Thanks #Talha!
My error was generated by the intent-filter tag. I have no idea why because in every topic that I saw everybody used that tag in Manifest file.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
So I remove it and add
[BroadcastReceiver]
[IntentFilter(new[] {Intent.ActionBootCompleted})]
to the BroadcastReceiver class.

Fatal Exception applicationId is null Parse

This is my second question in SO, I have a problem about Fatal Main error. Before I ask it, I found some other problem in SO, but what I found is about Facebook app
This is my error
java.lang.RuntimeException: applicationId is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
But, I have a class that declared it
package com.example.michael.eksperimen6chatting;
import android.app.Application;
import com.parse.Parse;
/**
* Created by Michael on 03/12/2015.
*/
public class ChattApp extends Application
{
#Override
public void onCreate()
{
super.onCreate();
Parse.initialize(this, "urkcFwvUmgSYvuOFTInJmkA3iWv0ArV3XT128TNb", "WvBC0cnGXHkVhTBbkFwLyxGDRgqR6qC8ft7DIleT");
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.michael.eksperimen6chatting" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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" >
</activity>
<activity android:name=".UserList"></activity>
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chat">
</activity>
</application>
</manifest>
Did I miss something here, can anyone help me? Gratia
Specifying ChattApp Application class name in your AndroidManifest.xml's <application> tag.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:name="com.example.michael.eksperimen6chatting.ChattApp">
....
</application>
import com.parse.Parse;
import android.app.Application;
public class ChattApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
}
AndroidManifest.xml
<application
android:name="com.example.michael.eksperimen6chatting.ChattApp"
.
.
.
</application>

BroadcastReceiver's behaviour for ACTION_SHUTDOWN

I have BroadcastReceiver which listens for ACTION_SHUTDOWN and some other actions.
My problem is, when I shutdown my android device(2.3.6) BroadcastReceiver is catching ACTION_SHUTDOWN two times. Problem is only with ACTION_SHUTDOWN and not with other actions.
When I run same code on emulator, it works fine.
Guys please help me. Here is my code:
my BootReceiver.java
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_SHUTDOWN.equalsIgnoreCase(intent.getAction())) {
Log.i("Boot Receiver - Shutdown event");
// database operation
}
if(Intent.ACTION_BOOT_COMPLETED.equalsIgnoreCase(intent.getAction())) {
// some operation
}
if(Intent.ACTION_AIRPLANE_MODE_CHANGED
.equalsIgnoreCase(intent.getAction().intern())) {
// some operation
}
if(ConnectivityManager.CONNECTIVITY_ACTION
.equalsIgnoreCase(intent.getAction())) {
// some operation
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.ui"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/spota"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.xyz.UserActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.xyz.BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.BATTERY_CHANGED" />
<action android:name="android.intent.action.AIRPLANE_MODE"/>
</intent-filter>
</receiver>
</application>
And here is the Logcat entries
05-03 16:37:23.826: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:23.881: I/xyz(2337): Inserting Data
05-03 16:37:28.514: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:28.529: I/xyz(2337): Inserting Data
Thanks!
you can add a flag to avoid this.
once you received this intent, set the flag.
if(flag)
{
do sth.
flag =0 ;
}
else
{
ignore.
}

how to restart android avd?

i want to catch the BOOT_COMPLETED action in my program, how to restart the AVD??
thanks in advance.....
package com.alex.app.testsysaction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("receiver", "system reboot completed.......");
}
}
the AndrdoiManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alex.app.testsysaction"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
</manifest>
Install application on AVD.
Close it and then restart it again manually.It will catch reboot action

Boot Receiver not working

Manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".AlarmActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<receiver android:name="CallReciver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE">
</action>
</intent-filter>
</receiver>
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="1000">
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:enabled="true"
android:name=".AlarmService">
</service>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="android.permission.WRITE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.READ_SMS">
</uses-permission>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
Receiver:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OnBootReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Log.d("Test","booot");
Toast.makeText(context, "Test", Toast.LENGTH_LONG).show();
}
}
Receiver doesn't work. I turn off and on my device and nothing happens.
SMS And Call Receiver in this project work good.
SMS Receiver and CallReceviver - works good.
First post updated - added full manifest.
If you have HTC device you also need to register for "android.intent.action.QUICKBOOT_POWERON". So the entry in manifest should be:
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
On my HTC, if I turn off the device and turn it on for a while I got QUICKBOOT_POWERON and no BOOT_COMPLETED.
If I turn off the device and remove the battery for a while - I got BOOT_COMPLETED after start.
Put permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Also know that in Android >= 3.1 the app gets installed in 'stopped' state and will not get boot and shutdown events until the user 'does something' with the app at least once. See this post on the topic.
Try this::
<receiver android:enabled="true" android:exported="true"
android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Cheers...!!!

Categories

Resources