I am Creating incoming call Receive activity by SipDemo . My activity has two button "accept call" and "reject call". When i got incoming call then my own activity is open such as
----> incoming call class ----> onReceive()----> go to my call pick activity.
here is this above two button such as accept and reject call. but when i hit on "accept call" . A Nullpointer Exception generate. it is on SipAudiocall incoming;
this is incoming class:-
static SipAudioCall incomingCall = null;
#Override
public void onReceive(final Context context, Intent intent) {
Intent startActivity = new Intent();
startActivity.setClass(context, Mycall.class);
startActivity.setAction(IncomingCallReceiver.class.getName());
startActivity.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(startActivity);
}
public static void acceptCall() {
incomingCall.sendDtmf(9);
try {
incomingCall.sendDtmf(9);
incomingCall.answerCall(200);
//wtActivity.gototimer("i");
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// wtActivity.gototimer("i");
}
public void rejectCaLL() {
try {
incomingCall.endCall();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This is my call pick activity class:-
public class Mycall extends Activity {
Button acct;
IncomingCallReceiver incomingCallReceiver;
#Override
public void onCreate(Bundle savedInstanceState) {
// Note that none of the preferences are actually defined here.
// They're all in the XML file res/xml/preferences.xml.
super.onCreate(savedInstanceState);
setContentView(R.layout.my);
acct = (Button) findViewById(R.id.button1);
acct.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IncomingCallReceiver.acceptCall();
}
});
}
}
This is AndroidManifest.xml :-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.sip">
<application android:icon="#drawable/icon" android:label="SipDemo">
<service android:name=".MService">
</service>
<activity android:name=".WalkieTalkieActivity"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SipSettings" android:label="set_preferences"/>
<receiver android:name=".IncomingCallReceiver" android:enabled="true" android:label="Call Receiver">
<intent-filter>
<action android:name="android.SipDemo.INCOMING_CALL" />
</intent-filter>
</receiver>
<activity android:name=".Mycall"
>
</activity>
<activity android:name=".Myclass"/>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
Please Expert Help me. I has involved this problem since 1 month.
I am wait for your response.
Thank you
Becouse your
IncomingCallReceiver incomingCallReceiver;
is null at time of calling it...
If you create a static class you must take care to initiate it maybe in creator-method.
create an abstract class:
public abstract class IncomingCallReceiver
and change your method to public static final
Related
The steps that explains the problem I faced are below;
1. I start the android application.
2. I put it on backgorund by pressing home button.
3. I turn the screen off.
4. I turn the screen on after some seconds.
5. My application suddenly becomes foreground. I realised that the application is forced to start again and the application class that I used is created again and then the start page of my application (this is login page) is shown although what page is opened before the step 2.
What I have tried so far is below;
I put configChanges and screenOrientation in all the activiy tags in my Androidmanifest.xml (I tried to put them one by one and both together also.)
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.Activity"
android:screenOrientation="nosensor"/>
I also tried to use screenOrientation="portrait" but didn't work.
My problem is related with the How do I disable orientation change on Android?, Prevent Android activity from being recreated on turning screen off and like others, but I could not find the solution of my problem yet.
Can you please help?
Edit 1: ********************************
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myproject"
android:versionCode="1"
android:versionName="1.0"
xmlns:tools="http://schemas.android.com/tools" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!-- Permission to use NFC -->
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc.hce"
android:required="true" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<permission android:name="com.myproject.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myproject.permission.C2D_MESSAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<!--
Add this permission to check which network access properties (e.g.
active type: 3G/WiFi).
-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Add this permission to access WLAN MAC address. -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Add this permission to access HW ID. -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:name="com.myproject.hce.MyApplication"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/MyAppTheme"
tools:replace="android:icon,android:theme"
>
<!-- Splash Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name=".Splash"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Login Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.LoginView"
android:screenOrientation="nosensor"
android:windowSoftInputMode="adjustResize" >
</activity>
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.MainView"
android:screenOrientation="nosensor" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/fb_app_id" />
<meta-data
android:name="com.crashlytics.ApiKey"
android:value="12h3g21h4v32hv43hv4" />
<service
android:name="com.myproject.pushnotifications.GCMIntentService"
android:enabled="true" >
</service>
<service
android:name="com.myproject.hce.McbpHceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" >
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<receiver
android:name="com.myproject.pushnotifications.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RETRY" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<service
android:name="com.myproject.hce.MyService"
android:exported="true"
android:enabled="true"
android:stopWithTask="false"/>
</application>
</manifest>
Application class
public class MyApplication extends Application {
private static MyApplication MyApplication;
private MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks;
public static MyApplication getMyApplication() {
return MyApplication;
}
#Override
public void onCreate() { //coko1
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "onCreate ...");
if (MyApplication == null)
MyApplication = this;
else
return;
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "super.onCreate() ...");
super.onCreate();
registerActivityLifecycleCallbacks(new MyLifecycleHandler());
setMyActivityLifeCycleCallbacks(new MyActivityLifeCycleCallbacks());
registerActivityLifecycleCallbacks(getMyActivityLifeCycleCallbacks());
}
public MyActivityLifeCycleCallbacks getMyActivityLifeCycleCallbacks() {
return MyActivityLifeCycleCallbacks;
}
public void setMyActivityLifeCycleCallbacks(
MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks) {
this.MyActivityLifeCycleCallbacks = MyActivityLifeCycleCallbacks;
}
}
Edit 2:****************
Splash.java
public class Splash extends Activity {
public static Context context;
public static final String LOG_TAG = "Splash ";
#Override
public void onCreate(Bundle bundle)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate...");
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); // catch unexpected error
super.onCreate(bundle);
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "MainView starts...");
Intent mainIntent = new Intent(Splash.this, MainView.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
}
MainView.class
public class MainView extends Activity {
Context context;
String LOG_TAG = "MainView ";
#Override
public void onCreate(Bundle savedInstanceState)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate ...");
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "LoginView starts...");
Intent loginIntent = new Intent(Splash.this, LoginView.class);
Splash.this.startActivity(loginIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
#Override
protected void onStart() {
super.onStart();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onStart ...");
};
#Override
protected void onPause() {
super.onPause();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onPause ...");
};
#Override
protected void onDestroy() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onDestroy ...");
super.onDestroy();
};
}
Edit 3:****************
I use fragments, maybe this will be the reason, but I am not sure.
The problem is due to a library I used. It works in background and makes the application restarts.
I suspend it when the application goes to background and resume it when it comes foregorund. That is it, the problem is solved.
Thanks you anyway.
I am working on Parse notifications..to send notifications to all users...The below code works well on emulator but the real device cannot get notifications....
Heres my code :
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpenedInBackground(getIntent());
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
ParseApplication.java
public class ParseApplication extends Application{
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Parse.initialize(this, "[APP ID]", "[CLIENT KEY]");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
Receiver.java
public class Receiver extends ParsePushBroadcastReceiver{
#Override
protected void onPushOpen(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Intent i = new Intent(arg0,MainActivity.class);
i.putExtras(arg1.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
}
AndroidManifest.xml
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.example.parse.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.parse.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:name="com.example.parse.ParseApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.example.parse.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>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.example.parse.Receiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
</manifest>
You do not have subscription set. If you haven't seen it already please follow the link. Parse Android Push Tutorial
In your Application onCreate:
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
As you may be creating your own sample app, pay close attention to the Manifest configuration, ensure you have right package names.
As noted in the Parse docs, they use GCM when Play-Services is available, which actual Android device will have. Where as they use persistent connection on devices without play-service ie. your emulator. Hope this helps.
I am making and application that records calls. Here is my code to record a call and save the file in the SD card under songs folder. But the problem is that this code was working fine but later it is not working. I cannot find what is the problem. Can you please help me out?
My Broad cast receiver:
public class BrCallReceive extends BroadcastReceiver {
#Override
public void onReceive(Context c, Intent i) {
Bundle extras = i.getExtras();
Intent x = new Intent (c, EavesDropperActivity.class);
x.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", state);
if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Log.w("DEBUG", "MATCHES");
Toast.makeText(c, "Launching record APP !", Toast.LENGTH_LONG).show();
c.startActivity(x);
}
}
}
}
My Recording activity:
public class EavesDropperActivity extends Activity {
/** Called when the activity is first created. */
MediaRecorder m_recorder = new MediaRecorder();
TelephonyManager t_manager ;
PhoneStateListener p_listener ;
String record_state;
Uri file;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Toast.makeText(getBaseContext(),
"Executing Activity",
Toast.LENGTH_LONG).show();
t_manager = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE);
p_listener = new PhoneStateListener() {
#Override
public void onCallStateChanged (int state, String incomingNumber) {
switch (state) {
case (TelephonyManager.CALL_STATE_IDLE) :
stop_recorder();
//t_manager.listen(p_listener, PhoneStateListener.LISTEN_NONE);
//finish();
break;
case (TelephonyManager.CALL_STATE_OFFHOOK) :
start_recorder();
break;
case (TelephonyManager.CALL_STATE_RINGING) :
break;
}
}
};
t_manager.listen(p_listener, PhoneStateListener.LISTEN_CALL_STATE);
return;
}
public void start_recorder () {
m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
m_recorder.setOutputFormat(OutputFormat.THREE_GPP);
m_recorder.setOutputFile(Environment.getExternalStorageDirectory()+"/songs/audionew.3gpp");
m_recorder.setAudioEncoder(AudioEncoder.AMR_NB);
try {
m_recorder.prepare();
m_recorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stop_recorder () {
m_recorder.stop();
m_recorder.release();
Uri file = Uri.fromFile(
new File(Environment.getExternalStorageDirectory(),"/songs/audionew.3gpp"));
Toast.makeText(getBaseContext(),
"record stored at " + file.toString(),
Toast.LENGTH_LONG).show();
t_manager.listen(p_listener, PhoneStateListener.LISTEN_NONE);
finish();
}
}
My manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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.testapp.EavesDropperActivity"
android:label="#string/app_name" >
</activity>
<receiver android:name="BrCallReceive" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
</application>
</manifest>
I think the broadcast receiver is not getting activated wile i am calling my phone.
How do you know your broadcast receiver is not working? Place a Log message inside onReceive() right at the beginning. It might be that your extras == null
But how to make my receiver functional now?
Check out example #5 and just follow the same steps.
Bro i dont think activity will get launched.
Well, it does: You are starting it in your onReceive():
Intent x = new Intent (c, EavesDropperActivity.class);
c.startActivity(x);
However, you are not setting any content in your Activity i.e no UI screen is presented because you have this line commented in onCreate() of EavesDropperActivity Activity:
//setContentView(R.layout.main);
So, you need to think hard on what you are trying to achieve in EavesDropperActivity
HTH.
Put this
<android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
in mainfest file for broadcast receiver.
Add your package name to your receiver class as,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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.testapp.EavesDropperActivity"
android:label="#string/app_name" >
</activity>
<receiver android:name="com.example.testapp.BrCallReceive" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
</application>
I have a BroadcastReceiver and I know how to reject calls. But I need help rejecting a call when I press the back button, because I have some sort of error in my code...
public class CallReceiveD extends BroadcastReceiver {
private ITelephony telephonyService;
public String phoneNumber;
public Bundle extras;
public TelephonyManager tm;
public Intent i;
#Override
public void onReceive(Context context, Intent intent) {
i=intent;
extras = intent.getExtras();
if (extras != null)
{
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast toast= Toast.makeText(context,phoneNumber, Toast.LENGTH_LONG);toast.show();
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
// telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//#Override
public void onBackPressed() {
telephonyService.endCall();
return;
}
}
My manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="denza12Des.call"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Call2BackActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CallReceiveD">
<intent-filter android:priority="99999">
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
as far as I know you cant use the backbutton onreceive event that u are using to decline call, but the back button press function i ok and it should work if you use it other than in the broadcast receive onReceive
I have a problem that I made a service which executes a task in background after every 5 seconds, for this I made a receiver in manifest and autostarter class but it is not excuted in my app. Means the service is not running in the app. I don't know why? Please suggest me for the right answer.
Android Manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name="com.halosys.TvAnyTime.ServiceAutoStarter">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainScreen"
android:label="#string/app_name" android:screenOrientation="portrait" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".IntroVideo" android:label="#string/app_name" android:theme="#style/CustomTheme" android:screenOrientation="landscape"/>
<activity android:name=".WelcomeScreen1" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
<activity android:name=".IntroFaceBookScreen" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
</application>
<uses-permission xmlns:android="http://schemas.android.com/apk/res/android"
android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.READ_INPUT_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk android:minSdkVersion="3" />
</manifest>
ServiceAutoStarter:
public class ServiceAutoStarter extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context, ServiceTemplate.class);
myIntent.putExtra("extraData", "somedata");
context.startService(myIntent);
}
}
ServiceTemplate.java:
public class ServiceTemplate extends Service {
Runnable refresher;
public static int HashesInPattern=32; // 32 64byte hashes in the pattern
public static int BytesInHash =64;
static byte[] hashPattern;
ArrayList<byte[]> finalHashafterXor = new ArrayList<byte[]>();
byte[] finaldatafile = new byte[2097152];
byte[] finalhash;
InputStream is;
byte[] bytesafterXor,bytes;
String strLine;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
//code to execute when the service is first created
}
#Override
public void onDestroy() {
//code to execute when the service is shutting down
}
#Override
public void onStart(Intent intent, int startid) {
//code to execute when the service is starting up
final Handler handler = new Handler();
refresher = new Runnable() {
public void run() {
// some action
try{
Encrypt();
Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
e.printStackTrace();
}
handler.postDelayed(refresher, 2000);
}
};
}
Thanks in advance.
I haven't gone through whole of your code but i saw manifest file
Like activities (and other components), you must declare all services in your application's manifest file.
Please do change and try.