本文整理了Java中android.content.Intent.getAction()
方法的一些代码示例,展示了Intent.getAction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getAction()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getAction
暂无
代码示例来源:origin: stackoverflow.com
// BroadcastReceiver when remove the device USB plug from a USB port
BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
usbConnected=false;
}
}
};
代码示例来源:origin: stackoverflow.com
public class LaunchReceiver extends BroadcastReceiver {
public static final String ACTION_PULSE_SERVER_ALARM =
"com.proofbydesign.homeboy.ACTION_PULSE_SERVER_ALARM";
@Override
public void onReceive(Context context, Intent intent) {
AppGlobal.logDebug("OnReceive for " + intent.getAction());
AppGlobal.logDebug(intent.getExtras().toString());
Intent serviceIntent = new Intent(AppGlobal.getContext(),
MonitorService.class);
AppGlobal.getContext().startService(serviceIntent);
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) {
//mLifecycleListener.onHide();
}
}
}
代码示例来源:origin: seven332/EhViewer
private void onInit() {
Intent intent = getIntent();
if (intent == null) {
return;
}
mAction = intent.getAction();
mFilename = intent.getStringExtra(KEY_FILENAME);
mUri = intent.getData();
mGalleryInfo = intent.getParcelableExtra(KEY_GALLERY_INFO);
mPage = intent.getIntExtra(KEY_PAGE, -1);
buildProvider();
}
代码示例来源:origin: lingochamp/FileDownloader
/**
* Parse the {@code intent} from the filedownloader broadcast.
*
* @param intent the intent from the broadcast.
* @return the file download model.
*/
public static FileDownloadModel parseIntent(Intent intent) {
if (!ACTION_COMPLETED.equals(intent.getAction())) {
throw new IllegalArgumentException(FileDownloadUtils.
formatString("can't recognize the intent with action %s, on the current"
+ " version we only support action [%s]",
intent.getAction(), ACTION_COMPLETED));
}
return intent.getParcelableExtra(KEY_MODEL);
}
代码示例来源:origin: stackoverflow.com
BroadcastReceiver broadcast_reciever = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
if (action.equals("finish_activity")) {
finish();
// DO WHATEVER YOU WANT.
}
}
};
registerReceiver(broadcast_reciever, new IntentFilter("finish_activity"));
代码示例来源:origin: stackoverflow.com
IntentFilter filter = new IntentFilter();
filter.addAction(KEY_NEXT);
// Add other actions as needed
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(KEY_NEXT)) {
nextSong();
} else if (...) {
...
}
...
}
}
registerReceiver(receiver, filter);
代码示例来源:origin: naman14/Timber
private void handleCommandIntent(Intent intent) {
final String action = intent.getAction();
final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null;
cycleShuffle();
} else if (UPDATE_PREFERENCES.equals(action)) {
onPreferencesUpdate(intent.getExtras());
代码示例来源:origin: facebook/facebook-android-sdk
if (CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION.equals(getIntent().getAction())) {
setResult(RESULT_CANCELED);
finish();
String chromePackage = getIntent().getStringExtra(EXTRA_CHROME_PACKAGE);
LocalBroadcastManager.getInstance(this).registerReceiver(
redirectReceiver,
new IntentFilter(CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION)
);
代码示例来源:origin: stackoverflow.com
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
IntentFilter iF = new IntentFilter();
iF.addAction("com.android.music.metachanged");
iF.addAction("com.android.music.playstatechanged");
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
String action = intent.getAction();
String cmd = intent.getStringExtra("command");
Log.d("mIntentReceiver.onReceive ", action + " / " + cmd);
String artist = intent.getStringExtra("artist");
String album = intent.getStringExtra("album");
String track = intent.getStringExtra("track");
Log.d("Music",artist+":"+album+":"+track);
代码示例来源:origin: stackoverflow.com
//Your activity will respond to this action String
public static final String RECEIVE_JSON = "com.your.package.RECEIVE_JSON";
private BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(RECEIVE_JSON)) {
String serviceJsonString = intent.getStringExtra("json");
//Do something with the string
}
}
};
LocalBroadcastManager bManager;
代码示例来源:origin: hidroh/materialistic
MaterialisticDatabase.getInstance(this).getLiveData().observe(this, mObserver);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
new IntentFilter(WebFragment.ACTION_FULLSCREEN));
mPreferenceObservable.subscribe(this, this::onPreferenceChanged,
R.string.pref_navigation);
mFullscreen = savedInstanceState.getBoolean(STATE_FULLSCREEN);
} else {
if (Intent.ACTION_VIEW.equalsIgnoreCase(intent.getAction())) {
mItemId = AppUtils.getDataUriId(intent, PARAM_ID);
} else if (intent.hasExtra(EXTRA_ITEM)) {
mItem = intent.getParcelableExtra(EXTRA_ITEM);
mItemId = mItem.getId();
代码示例来源:origin: stackoverflow.com
BroadcastReceiver form_filled = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String received_action = intent.getAction();
if (received_action.equals("form_filled")) {
Bundle bundle = intent.getExtras();
// GET ALL DATA FROM BUNDLE.
}
}
};
registerReceiver(form_filled, new IntentFilter("form_filled"));
代码示例来源:origin: stackoverflow.com
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Message msg = Message.obtain();
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action)){
Toast.makeText(context, "ACTION_FOUND", Toast.LENGTH_SHORT).show();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
try
代码示例来源:origin: stackoverflow.com
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && TextUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION) ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && TextUtils.equals(intent.getAction(), CONNECTIVITY_ACTION_LOLLIPOP)) {
if (intent.getExtras() != null) {
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
Log.d("receiver test", "detected on");
}
}
Log.d("receiver test", Boolean.toString(intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY)));
if (intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) {
Log.d("receiver test", "detected off");
}
}
}
};
代码示例来源:origin: seven332/EhViewer
@Override
public void onReceive(Context context, Intent intent) {
if (mTimeZone == null && Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
final String timeZone = intent.getStringExtra("time-zone");
createTime(timeZone);
}
onTimeChanged();
}
};
代码示例来源:origin: commonsguy/cw-omnibus
@Override
protected void onNewIntent(Intent intent) {
if (inWriteMode &&
NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag tag=intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] url=buildUrlBytes(getIntent().getStringExtra(Intent.EXTRA_TEXT));
NdefRecord record=new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
NdefRecord.RTD_URI,
new byte[] {}, url);
NdefMessage msg=new NdefMessage(new NdefRecord[] {record});
new WriteTask(this, msg, tag).execute();
}
}
代码示例来源:origin: stackoverflow.com
public class SmsListener extends BroadcastReceiver{
private SharedPreferences preferences;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
}
}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
}
}
代码示例来源:origin: stackoverflow.com
public void onReceive(final Context context, final Intent intent) {
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo networkInfo =
intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if(networkInfo.isConnected()) {
// Wifi is connected
Log.d("Inetify", "Wifi is connected: " + String.valueOf(networkInfo));
}
} else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
NetworkInfo networkInfo =
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
! networkInfo.isConnected()) {
// Wifi is disconnected
Log.d("Inetify", "Wifi is disconnected: " + String.valueOf(networkInfo));
}
}
}
代码示例来源:origin: stackoverflow.com
public class MainActivity extends Activity {
IntentFilter filter1;
@Override
public void onCreate() {
filter1 = new IntentFilter("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED");
registerReceiver(myReceiver, filter1);
}
//The BroadcastReceiver that listens for bluetooth broadcasts
private final BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equalsIgnoreCase("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED")) {
Log.d(TAG,"Bluetooth connect");
}
}
};
@Override
public void onDestroy() {
unregisterReceiver(myReceiver);
}
}
内容来源于网络,如有侵权,请联系作者删除!