before everything, I search in this site and google but I still have problem , so I need your help please.
I want to know how can I use volume keys while phone is Locked? I'm using this code and while phone is not locked it's work good but not when it's locked.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
// Do something
// return true because we want handle this key
return true;
}
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
// Do something
// return true because we want handle this key
return true;
}
I know I have to use BroadcastReceiver for this matter. but, I want to know how? if you guys give me live example or some kind of tutorial that I can use.
I added this to my manifest file
<receiver
android:name=".CountReciever"
android:process=":remote" >
<intent-filter>
<action android:name="AddedCounting" />
</intent-filter>
</receiver>
and created this activity
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class CountReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent k2) {
// TODO Auto-generated method stub
Toast.makeText(context, "received!", Toast.LENGTH_LONG).show();
Log.i("in REceiver", "OHAAAHA");
Intent intent = new Intent(context,AddedCounting.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
and in AddedCounting activity I have the piece of code that I added at the beginning of this post to control volume keys.
but it's still not working. if you guys can help on it I really appreciate it.
Last but not least, I don't receive any error.
Thank you for all of your help and time.