I am new to android ,how can I know if the call button is pressed or i can replace default dialer activity using my dialer I have used following code
<receiver android:name="CallService">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
</intent-filter>
</receiver>
and here is my broadcast
public void onReceive(Context context, Intent intent)
{
String mAction = intent.getAction();
Log.e("Intent", mAction);
}
But its not receiving any intent
Related
I used this permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and the receiver is:
<receiver android:name=".auth.NotificationBroadcast" android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
and receiver in code is:
#Override
public void onReceive(Context context, Intent intent) {
System.out.println("BroadcastReceiverBroadcast--------------------ReceiverBroadcastReceiverBroadcastReceiver----------------BroadcastReceiver");
if (intent != null) {
String action = intent.getAction();
switch (action) {
case Intent.ACTION_BOOT_COMPLETED:
System.out.println("Called on REBOOT");
// start a new service and repeat using alarm manager
break;
default:
break;
}
}
}
After reboot it's still not getting called in lollipop, but on marshmallow it's running.
try to put this line in your receiver's intent-filter.
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
If your application is installed on the SD card, you should register this to get the android.intent.action.BOOT_COMPLETED event.
Updated: Since your app is using alarm service, it should not be installed on external storage. Reference: http://developer.android.com/guide/topics/data/install-location.html
Whenever the platform boot is completed, an intent with android.intent.action.BOOT_COMPLETED action is broadcasted. You need to register your application to receive this intent. For registering add this to your AndroidManifest.xml
<receiver android:name=".ServiceManager">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
So you will have ServiceManager as broadcast receiver to receive the intent for boot event. The ServiceManager class shall be as follows:
public class ServiceManager extends BroadcastReceiver {
Context mContext;
private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
#Override
public void onReceive(Context context, Intent intent) {
// All registered broadcasts are received by this
mContext = context;
String action = intent.getAction();
if (action.equalsIgnoreCase(BOOT_ACTION)) {
//check for boot complete event & start your service
startService();
}
}
private void startService() {
//here, you will start your service
Intent mServiceIntent = new Intent();
mServiceIntent.setAction("com.bootservice.test.DataService");
mContext.startService(mServiceIntent);
}
}
Since we are starting the Service, it too must be mentioned in AndroidManifest:
<service android:name=".LocationService">
<intent-filter>
<action android:name="com.bootservice.test.DataService"/>
</intent-filter>
</service>
recently I use BOOT_COMPLETED 2 app (A app, and B app)
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
A app is activity and B app is service app
when my device boot,
first A app launch and B app launch
so, show B app screen.
I want
first B app launch and A app launch showing A app screen
perhaps, Can I give BOOT_COMPLETED Priority is possible?
finally, I want when I boot my device, show A app screen
Thanks!
add
I try
B app(service)
public class BootCompletedReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) {
Intent i = new Intent("A app package name.BOOT_COMPLETED");
context.sendBroadcast(i);
}
}
}
<receiver android:name=".BootCompletedReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
A app(activity)
public class BootSendReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context,Intent intent) {
if( intent.getAction().equals("B app packagename.BOOT_COMPLETED"));
Intent i = new Intent (context, MainActivity.class);
context.startActivity(i);
}
}
<receiver android:name=".BootSendReceiver">
<intent-filter>
<action android:name="blackeyeonandroid.iosystem.co.kr.simpleserviceexample.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
and I try boot .. but showing B app screen
I think you can not control that..
Instead, you can make APP1 start the APP2. This way, only APP1 receives the BOOT_COMPLETE message. Then, APP1 is responsible to send a new intent to start APP2:
Maybe, you can do as follows (note that APP2 does not receive android's default BOOT_COMPLETED message):
APP1
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".AppToStartFirstBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Receiver
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent("com.example.mytestapp.BOOT_COMPLETED");
context.sendBroadcast(i);
}
}
APP2
Manifest:
<receiver android:name=".AppToStartLaterBroadcastReceiver">
<intent-filter>
<action android:name="com.example.mytestapp.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Receiver
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.example.mytestapp.BOOT_COMPLETED")) {
// Do what you want in secundary APP
}
}
Note
This is an suggestion and you should adjust to your case. Since I don't have more details about your code, you may need to modify it to your case.. But you can use the idea.
I want to develop app that doesn't have icon launcher. The app will run alarmscheduler which triggered when app is installed or phone is rebooted.
The problem is how can I open the activity since the app doesn't have intent filter like below:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Is there a way to handle dial code such as ##4635*#*# to open the activity ?
or any other solutions are welcomed.
You can do it with two ways:
1) as answer by #KishuDroid
2) By define code in manifest
public class MySecretCodeReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
In manifest file
<receiver android:name=".MySecretCodeReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="4635" />
</intent-filter>
</receiver>
Note:
In Second method you must have to dial *#*#your_code#*#* and dont need to press call button
But in first method you can customise your prefix or postfix of code. For example *#your_code# or **your_code##. but you need to press call button.
You have to use Broadcast Receiver...
public class OutgoingCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("OutgoingCallReceiver",phonenumber);
Log.i("OutgoingCallReceiver",bundle.toString());
if(code.equals("#056700") {
intent.setComponent(new ComponentName("com.example", "com.example.yourActivity"));
And Your Android Manifest
<receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
Also, include the permission:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I found lots of threads about this topic, however I'm not able to solve my problem. Here is the code:
The manifest file:
<service
android:name="com.xxx.player.MediaPlayerService.MediaPlayerService"
android:enabled="true" >
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
<receiver android:name="com.xxx.player.MediaPlayerService.MediaPlayerService$ServiceBroadcastReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="#string/ACTION_PREPARE_AND_PLAY_NEW_FILE"/>
<action android:name="#string/ACTION_PREPARE_NEW_FILE"/>
<action android:name="#string/ACTION_START"/>
<action android:name="#string/ACTION_STOP"/>
<action android:name="#string/ACTION_PAUSE"/>
<action android:name="#string/ACTION_SEEK_TO"/>
<action android:name="#string/ACTION_RELEASE"/>
</intent-filter>
</receiver>
</service>
The broadcast class:
public class MediaPlayerService extends Service implements
MediaPlayer.OnErrorListener,
AudioManager.OnAudioFocusChangeListener,
Runnable,
SeekBar.OnSeekBarChangeListener {
...
public class ServiceBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Toast.makeText(getApplicationContext(), "action: " + action, 30000000).show();
if (action.equals(Resources.getSystem().getString(R.string.ACTION_PREPARE_AND_PLAY_NEW_FILE))) {
prepareAndPlayNewFile(intent.getStringExtra("mediaData"));
}
}
}
}
The way I submit the intent:
private void prepareAndPlayNewFile(String mediaData) {
Intent myIntent = new Intent();
myIntent.setAction(context.getString(R.string.ACTION_PREPARE_AND_PLAY_NEW_FILE));
myIntent.putExtra("mediaData", mediaData);
context.sendBroadcast(myIntent);
}
Instead of approaching your playing of media this way, you should instead bind your Service to your Activity instead of using a broadcast receiver for message passing.
Also you shouldn't be using #string/VAR1 (which I'm not sure if intent filters work with that kind of string definition) for your intent actions it ALWAYS should be the constant string such as:
android.intent.action.BLAH
I am developing a calendar widget, and I can't receive the DATE_CHANGED message when I changed the date MANUALLY.
What is the problem?
My code in Manifest is :
<receiver android:name="com.widget.calendar.CalendarWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.DATE_CHANGED"/>
</intent-filter>
<!-- This specifies the widget provider info -->
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widgetinfo" />
</receiver>
And I tried to receive it like this:
#Override
public void onReceive(Context ctx, Intent intent) {
final String action = intent.getAction();
if (action.equalsIgnoreCase("android.intent.action.DATE_CHANGED")) {
Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
super.onReceive(ctx, intent);
}
But the log is not print when I change the system date manually.
Thanks!
UPDATE:
I solved this with Intent.ACTION_TIME_CHANGED, It's really a bug of DATE_CHANGED.
Use this intent:
<intent-filter>
<action android:name="android.intent.action.TIME_SET"/>
</intent-filter>
And receive:
#Override
public void onReceive(Context ctx, Intent intent) {
final String action = intent.getAction();
if (action.equalsIgnoreCase("android.intent.action.TIME_SET")) {
Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
super.onReceive(ctx, intent);
}