I want to use BroadcastReceiver like this
<receiver android:name=".receivers.MediaReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.hardware.action.NEW_PICTURE" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.hardware.action.NEW_VIDEO" />
<data android:mimeType="video/*" />
</intent-filter>
</receiver>
I had read Using the JobScheduler API on Android Lollipop,but I still don't know how to do.
I'm not sure if this was your original question, but I came across this because of the deprecation of WakefulBroadcastReceiver, which was previously the standard way of listening for an intent and then doing activity that requires a wake lock.
The answer is that you should still use BroadcastReceiver to receive intents like you've set in the intent-filter. If you need a wake lock, which you likely don't, then schedule a job from your BroadcastReceiver instead of using a WakefulBroadcastReceiver.
Related
i don't know if this is okay having two broadcast receivers in my android app. I separated them cause the one receiver with the boot_completed, it will do a different task and the other receiver with also do different task when they receive a broadcast.
<receiver android:name=".Autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".AlarmManagerBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
That is perfectly valid you should always try to seperate your concerns which part of a good architecture/good design principles.
What happens when we click the default message app in android.I mean does it broadcast an intent? Actually I am trying to make an app that will ask for a password in an new activity when user clicks on message icon and is redirected to list of messages only if password is correct.But my activity is not shown.Here is how I am trying to do it.Added a receiver in manifest.
<receiver android:name="Receiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.GET_CONTENT">
</action>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType = "vnd.android-dir/mms-sms" />
</intent-filter>
</receiver>
You are asking about "launching" an activity. Typically that is done with an intent created as such:
Intent launch = new Intent(Intent.ACTION_MAIN);
launch.setPackage("com.your.package.name");
startActivity(launch);
Because the package name is set, you cannot intercept this intent. It is not broadcast to any receiver.
If you write a launcher app, you could intercept such a launch request and launch a different app in front of it. But it would not really be possible to prevent users from side-stepping this by returning to the default Android launcher.
However, there are several other means of "launching" the "default" SMS app. For example, an app that requests an SMS be sent through the default SMS app will create an intent like this:
Intent launch = new Intent("android.intent.action.SENDTO");
There are several others as well. And your app can register an activity for these intent in the manifest like this:
<activity
android:name="com.your.package.name.MyMessageActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android-dir/mms-sms" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
In Android KitKat a user must actually set your app as the "Default SMS App" in order for it to be able to write to the SMS provider/database and also to receive the "SMS_DELIVER" intent. In all versions of Android, any app can register for the "SMS_RECEIVED" intent but in KitKat+ it cannot be aborted, like in earlier versions.
You may notice that one filter specified above is similar to yours - using mimeType "vnd.android-dir/mms-sms" as a "DEFAULT" action. This places your app as one option for the user to "Complete Action Using" when, for example, they select a contact they want to message.
If you do all of this, then your activity can require a password in order to "view" messages. However, you should be aware that unless you are using a separate data store for the messages, all SMS can be read through the MMS-SMS provider (assuming the app has requested permission to do so).
What you are trying to achieve is not possible, please see this:
https://stackoverflow.com/a/21469133/2452039
You cannot prevent native applications from opening with an outside app. The only thing you could do would be to intercept incoming messages, preventing them from reaching the SMS app inbox, and store them in your application, and there you could prevent them from opening. I must warn you that since API level 19 that is no longer possible...
My Question is how can I add my application to the android default Dialer selection, to be more specific without using the android.intent.action.CALL_PRIVILEGED?
Now I am using this code below, this works fine:
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
HOWEVER Google recently posted: http://productforums.google.com/forum/#!topic/mobile/wXqnbynsL8Y
And mailed this to the programmes who does use the intent android.intent.action.CALL_PRIVILEGED:
Issue:
Users of your application may not be able to make emergency
phone calls through the system phone dialer if they've elected to have
your application route calls. As noted in the documentation,
applications that listen for the CALL_PRIVILEGED Intent action will
intercept emergency service calls from the system, but may not be able
to route them properly. Please note that CALL_PRIVILEGED is a
restricted API, not intended for use within third party applications
that cannot route emergency calls properly.
Solution:
• Remove CALL_PRIVILEGED from Intent filters in Java code and AndroidManifest.xml.
• Update your Google Play listing
description to include a statement that using your app as a default
dialer may interfere with dialing 911 emergency services.
The easiest solution my be deleting but then the application would use functionality. But is there another way to add the application to the default Dialer selection? but then without the CALL_PRIVILEGED intent?
Thanks in advance
Just an example of the default Dialer selection
Edit:
My other intents that I use:
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
More important is that privileged call action is needed in intent filter with data as "tel" for uri.
Also below permission tag is need to allow phone call.
Missing in your code in category Launcher.
<uses-permission android:name="android.permission.CALL_PHONE" />
You don't need to intercept CALL_PRIVILEGED to make a dialer. There are 3 intents of interest:
ACTION_DIAL: invokes the dialer. You should intercept this.
CALL: places a call. I suppose you need to intercept this if you are routing the call via VoIP, else just pass it on to the system.
CALL_PRIVILEGED: places an Emergency call (911 in US etc). You don't need to intercept this, since these calls are routed specially, even without a SIM card, and without charging the user.
For what it's worth, I got the same email from Google. My app doesn't even use CALL or CALL_PRIVILEGED intents. There was however, a check in the code that the passed intent was not this action (just for the sake of completeness). So, I think they just scan the data section of the apk to see if this string is used anywhere.
Edit try this, it works for my app:
<activity android:name=".ActivityName"
android:label="#string/activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:targetActivity="fully.qualified.ActivityName"
android:name="fully.qualified.ActivityName_HTC_hack"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity-alias>
Try "android.intent.action.DIAL". The user has to start the call manually, but i think it's the best solution.
Input: If nothing, an empty dialer is started; else getData() is URI of a phone number to be dialed or a tel: URI of an explicit phone number.
ref: developer page
I would like to make a link in Android browser to be able to call a receiver.
I read this post on how to make a link start my app and tries to do the same for my startup receiver receiver, but it didn't work.
Is it possible?
My receiver is configured as follows:
<receiver
android:name="com.wiziapp.wiziappweb.app.MyStartupIntentReceiver"
android:label="#string/search" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
<intent-filter>
<data android:scheme="myapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</receiver>
The link I use to test it is:
Enable notification
I would like to make a link in Android browser to be able to call a receiver.
That is not possible.
My receiver is configured as follows:
ACTION_VIEW is used with startActivity(), not sendBroadcast(), so your second <intent-filter> is unlikely to ever be used.
The link I use to test it is
Links only call startActivity(), not sendBroadcast(). Your are welcome to have the link point to a Theme.NoDisplay activity that sends the broadcast and then calls finish() to go away.
In my application I have a service that after for example 30 seconds, runs another activity. I did this process with Alarm Manager.
But the problem is, if the user changes the system time it affects 30 seconds. What is your suggestion? Is there any way to know if the user changes the system time?
You can listen to Intent.ACTION_DATE_CHANGED broadcast. Your ApplicationManifest file should contain something like
<receiver android:name="com.test.YouBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
</intent-filter>
</receiver>
For broadcast receivers refer:
http://developer.android.com/reference/android/content/BroadcastReceiver.html