How to receive brocast with VOICEMAIL - android

http://developer.android.com/reference/android/provider/VoicemailContract.html
i don't know how to make a brocast receiver with VOICEMAIL. When you receive a voicemail,you will see "NEW VOICEMAIL" in notification,the icon just like a tape.
here is my code:
AndroidManifest.xml
<receiver android:name=".VoiceBrocast" >
<intent-filter>
<action android:name="android.intent.action.NEW_VOICEMAIL" />
</intent-filter>
</receiver>
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
i tried to register in xx.java,but it's no works.
MainActivity.java:
protected VoiceBrocast mUiBroadcastReceiver;
mUiBroadcastReceiver = new VoiceBrocast();
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction("android.intent.action.ACTION_NEW_VOICEMAIL");
MainActivity.this.registerReceiver(mUiBroadcastReceiver, mIntentFilter);
VoiceBrocast.Java
public class VoiceBrocast extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("voicemail");
}
}
when i received a voicemail, nothing to print, i can't see "voicemail" in LogCat.

Not sure that else is wrong, but one problem is: the intent action is not called "android.intent.action.ACTION_NEW_VOICEMAIL" but "android.intent.action.NEW_VOICEMAIL".
Perhaps you mixed it up with the constant name on the VoicemailContract class which is VoicemailContract.ACTION_NEW_VOICEMAIL.

The minimum permission needed to access this content provider is ADD_VOICEMAIL
Do you have such permission ?

Related

Make my app receive a phone call notification

My app need to know if the user is current on a phone call or not, then do some response accordingly.
All I need to know if the user is on a phone call or not. I do not need any other rights to deal with anything related to the phone number or any personal information of the user.
What should I do to achieve this? Do I need to get user's permission for it?enter code here
Yes First add these permission to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
You should use Broadcast Receiver with this intent filters.
android.intent.action.NEW_OUTGOING_CALL
android.intent.action.NEW_INCOMING_CALL
You can use service for this register. Something like these:
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
registerReceiver(receiver,new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"));
registerReceiver(receiver2,new IntentFilter("android.intent.action.NEW_INCOMING_CALL"));
return START_STICKY;
}
And our Broadcast receiver you can use this:
public class CallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//
RequestQueue
String savedNumber="";
String savedNumber2= intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
Log.e("Saved number","Numara: "+savedNumber);
Log.e("İt is ","İt is it");
Log.e("Saved number 2 ",savedNumber2);
}
}
And lastly in your manifest file you could use intent filter in your receiver like these:
<receiver
android:name=".CallReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>

Register a Local BroadcastReceiver in AndroidManifest.xml?

Is there anyway to register a BroadcastReceiver in AndroidManifest.xml and receives broadcast that is send by a LocalBroadcastManager?
Currently I must call
registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
to register a Receiver, declare in AndroidManifest.xml won't work. But this means I must know exactly the receiver's package name and class name, not just the intent filter. Is it possible to declare the receiver in the manifest file?
following is my current code.
AndroidManifest.xml:
...
<receiver
android:name="com.example.test.MessageReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.m2x.test.intent.MESSAGE_RECEIVED" />
</intent-filter>
</receiver>
...
MainActivity.java:
Intent intent = new Intent();
intent.setAction("com.m2x.test.intent.MESSAGE_RECEIVED");
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mContext.get());
manager.sendBroadcast(intent);
MessageReceiver.java
public class MessageReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.m2x.test.intent.MESSAGE_RECEIVED")) {
Toast.makeText(context, "user message received", Toast.LENGTH_SHORT).show();
}
}
}
No, you can't.
The local BroadcastReceiver isn't a real BroadcastReceiver, basically its a list of callbacks functions.
You can check the source code of LocalBroadcastManager.java.

Monitoring network connection type change in Android Service

I want to capture the network connection type change in Android Service and run a code of this Service when the event fires. How to do that inside a Service class only without separate class? I have this code, but it doesn't work.
BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
playlist="NETWORK TYPE CHANGED";
}
};
public void playSong(Context c, String url) {
try
{
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filter);
Your BroadcastReceiver needs to receive the Intent from the system, so you need to register your BroadcastReceiver in your AndroidManifest
<receiver
android:name=".ConnectivityReceiver
android:exported="false" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
and do not forget the permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

How can I track an APK install

I'm trying to track an APK install. When a user lands on the downloadpage (not the store), he is coming from a specific source. When user clicks on download, the APK will be installed. After it's installed, I need to map the install to the source the user was coming from before installing. Is there any good way to do this?
My plan so far: Save the user IP and screen resolutions on the download page to a database. After install, pass IP and screen resolution to the server and map with the row in the database. Is this a good way of doing this?
Hope you guys can help me.
You just need to write a BroadcastReceiver for this which can receive the PACKAGE_ADDED and PACKAGE_INSTALL Intent:
InstallBroadcastReceiver.Class
public class InstallBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(Intent.ACTION_PACKAGE_ADDED)
||action.equals(Intent.ACTION_PACKAGE_INSTALL)){
notifyServerForApplicationInstall(context, intent);
}
}
private void notifyServerForApplicationInstall(Context context,Intent intent){
//send the data to your server here
}
}
Register the receiver in AndroidManifest file
<receiver
android:name=".InstallBroadcastReceiver"
android:exported="false"
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Don't forget to give this permissions in manifest :
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
I have prepared a BroadcastReceiver class :
public class newPackageReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("DEBUG"," test for application install/uninstall");
}
}
In the main activity, I first register a new receiver object, then instanciate button for application install.
public void onCreate(Bundle savedInstanceState) {
...
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
receiver = new newPackageReceiver();
registerReceiver(receiver, filter);
...
dlButton.setText(R.string.dl_button);
dlButton.setOnClickListener(new AppliDownloadOnClickListener(this ));
#Override
public void onDestroy(){
unregisterReceiver(receiver);
super.onDestroy();
}

broadcast receiver for ACTION_CAMERA_BUTTON never gets called

I have an app in android in which I wanna take a photo when physical hardware button for camera gets pressed.I registered an intent for this type of action but my broadcast receiver never gets called.
Here is how I did it:
class that extends BroadcastReceiver
public class Adisor extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != null) {
// prevent the camera app from opening
abortBroadcast();
System.out.println("HEY");
mCamera.takePicture(null, mPictureCallback, mPictureCallback);
}
}
}
Here is where I register my receiver to listen for actions:
protected void onResume() {
Log.e(TAG, "onResume");
super.onResume();
drb = new Adisor();
IntentFilter i = new IntentFilter(
"android.intent.action.CAMERA_BUTTON"
);
registerReceiver(drb, i);
}
And in my manifest file I have this:
<activity android:name=".TakePhoto" />
<receiver android:name=".Adisor" >
<intent-filter android:priority="10000">
<action android:name="android.intent.action.CAMERA_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
The name of the activity in which I'm doing all this is:TakePhoto.My question is why my onReceive() method never gets called!
Neither this:
System.out.println("HEY");
appears in my logcat or the method
System.out.println("HEY");
mCamera.takePicture(null, mPictureCallbacmPictureCallback);
gets called!
What I'm doing wrong?
You should either have the receiver registered in the manifest or register programmatically. Remove the registerReceiver() call from the onResume method.
Edit:
Add these to your manifest.
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
Your intent filter should never have a priority of 10000. The maximum allowed for user applications is 999.
See setPriority(int) on the AndroidDev website.
For opening the only the camera of your application you can use intent like:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, ACTION_IMAGE_CAPTURE);

Categories

Resources