List of usage examples for android.content Intent EXTRA_KEY_EVENT
String EXTRA_KEY_EVENT
To view the source code for android.content Intent EXTRA_KEY_EVENT.
Click Source Link
From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java
private void answerCall(boolean isSpeakon) { Context context = getApplicationContext(); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // ??//from www . j a v a 2s.co m if (!(audioManager.isWiredHeadsetOn() || audioManager.isBluetoothA2dpOn())) { // 4.1??? 4.1??Permission Denial: not allowed to // send broadcast android.intent.action.HEADSET_PLUG from pid=1324, // uid=10017 // ??????android.permission.CALL_PRIVLEGED?????4.1??????????NULL?? Constants.log("speakerset", String.format("AudioManager before mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK); meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent); context.sendOrderedBroadcast(meidaButtonIntent, "android.permission.CALL_PRIVILEGED"); /*TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class<TelephonyManager> c = TelephonyManager.class; Method mthAnswerCall; try { mthAnswerCall = c.getDeclaredMethod("getITelephony", (Class[]) null); mthAnswerCall.setAccessible(true); ITelephony iTel = (ITelephony) mthAnswerCall.invoke(telMag, (Object[]) null); iTel.answerRingingCall(); } catch (Exception e) { e.printStackTrace(); }*/ if (isSpeakon) { try { Thread.sleep(500); } catch (InterruptedException e) { Constants.log("speakerset", "Problem while sleeping"); } Constants.log("speakerset", "AudioManager answer mode:" + audioManager.getMode() + " speaker mod:" + String.valueOf(audioManager.isSpeakerphoneOn())); while (audioManager.getMode() != AudioManager.MODE_IN_CALL) { try { Thread.sleep(300); } catch (InterruptedException e) { Constants.log("speakerset", "Problem while sleeping"); } } // audioManager.setMicrophoneMute(true); audioManager.setSpeakerphoneOn(true); // audioManager.setMode(AudioManager.MODE_IN_CALL); Constants.log("speakerset", String.format("AudioManager set mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); } } else { Constants.log("speakerset", String.format("AudioManager before mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK); meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent); context.sendOrderedBroadcast(meidaButtonIntent, "android.permission.CALL_PRIVILEGED"); } }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** Return notification remote views * /*from w ww. ja v a 2 s .co m*/ * @return [views, bigViews] */ public RemoteViews[] getNotificationViews() { Bitmap b = getAlbumBitmap(); RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded); RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar); if (b != null) { bigViews.setImageViewBitmap(R.id.status_bar_album_art, b); views.setViewVisibility(R.id.status_bar_icon, View.GONE); views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE); views.setImageViewBitmap(R.id.status_bar_album_art, b); } else { views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE); views.setViewVisibility(R.id.status_bar_album_art, View.GONE); } ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.putExtra(CMDNOTIF, 1); mediaButtonIntent.setComponent(rec); KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 2); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 4); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 3); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); views.setTextViewText(R.id.status_bar_track_name, getTrackName()); bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName()); views.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName()); return new RemoteViews[] { views, bigViews }; }