本文整理汇总了Java中android.content.IntentFilter类的典型用法代码示例。如果您正苦于以下问题:Java IntentFilter类的具体用法?Java IntentFilter怎么用?Java IntentFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntentFilter类属于android.content包,在下文中一共展示了IntentFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.content.IntentFilter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
s = new Setting();
Language = s.getLang();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Language = preferences.getString("l",Language);
setLanguage(Language);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
fm=getSupportFragmentManager();
fm.beginTransaction().add(R.id.content,new BlankFragment()).commit();
Intent i = new Intent(this,SocketService.class);
bindService(i,myConnection,Context.BIND_AUTO_CREATE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.e("Brodcast","Broadcast intent onCreate invoked");
if(savedInstanceState == null){
if(!registred){
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("my-event"));
Log.e("Registre","Broadcast intent register");
registred = true;
}}
}
示例2: registerReceiver
import android.content.IntentFilter; //导入依赖的package包/类
private void registerReceiver() {
if (mRegisteredTimeZoneReceiver) {
return;
}
mRegisteredTimeZoneReceiver = true;
IntentFilter filter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
MyWatchFace.this.registerReceiver(mTimeZoneReceiver, filter);
}
示例3: start
import android.content.IntentFilter; //导入依赖的package包/类
public void start(Context context, List<App> appsToMonitor) {
this.context = context;
this.appsToMonitor = appsToMonitor;
this.lastSeenRunningApps = new ArrayList();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.SCREEN_OFF");
filter.addAction("android.intent.action.SCREEN_ON");
filter.addAction(ACTION_MONITOR_APPS);
this.receiver = new AppMonitorReceiver();
context.registerReceiver(this.receiver, filter);
if (((PowerManager) context.getSystemService("power")).isScreenOn()) {
startMonitoring();
}
}
示例4: startBluetoothServices
import android.content.IntentFilter; //导入依赖的package包/类
/**
* Starts bluetooth and listens to pairing requests and bluetooth state changes
*/
public static void startBluetoothServices() {
mReceiver = new BluetoothReceiver();
//Register the BroadcastReceiver for multiple bluetooth actions
//when another bluetooth device is discovered in range
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
//when discovering action finishes (discovering means that bluetooth searches for nearby devices)
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
//when bluetooth changes from on to off
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
//when another device requests pairing with this device
filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
mainActivity.mainRegisterReceiver(mReceiver, filter);
if(!started) {
//tries to start bluetooth if it is not on
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter!=null){
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
mainActivity.startActivityForResult(enableBtIntent, MainActivity.BLUETOOTH_ON);
} else {
started = true;
}
}
}
}
示例5: onCreate
import android.content.IntentFilter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usb);
mStatusView = (TextView) findViewById(R.id.text_status);
mResultView = (TextView) findViewById(R.id.text_result);
mUsbManager = getSystemService(UsbManager.class);
// Detach events are sent as a system-wide broadcast
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbReceiver, filter);
handleIntent(getIntent());
}
示例6: requestPushToken
import android.content.IntentFilter; //导入依赖的package包/类
void requestPushToken(Activity activity){
if (activity!=null) {
Intent service = new Intent(activity, RegistrationIntentService.class);
service.putExtra(RegistrationIntentService.TOKEN, "token");
activity.startService(service);
IntentFilter intentFilter = new IntentFilter(RegistrationIntentService.ACTION_TOKEN);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
activity.registerReceiver(tokenBroadcastReceiver, intentFilter);
//send back first
sendBroadCast();
}
else{
}
}
示例7: protectIntentFilter
import android.content.IntentFilter; //导入依赖的package包/类
public static void protectIntentFilter(IntentFilter filter) {
if (filter != null) {
List<String> actions = mirror.android.content.IntentFilter.mActions.get(filter);
ListIterator<String> iterator = actions.listIterator();
while (iterator.hasNext()) {
String action = iterator.next();
if (SpecialComponentList.isActionInBlackList(action)) {
iterator.remove();
continue;
}
if (SYSTEM_BROADCAST_ACTION.contains(action)) {
continue;
}
String newAction = SpecialComponentList.protectAction(action);
if (newAction != null) {
iterator.set(newAction);
}
}
}
}
示例8: hasSpecializedHandlerIntents
import android.content.IntentFilter; //导入依赖的package包/类
/**
* Used to check whether there is a specialized handler for a given intent.
* @param intent The intent to check with.
* @return Whether there is a specialized handler for the given intent.
*/
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
try {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> handlers = pm.queryIntentActivities(
intent,
PackageManager.GET_RESOLVED_FILTER);
if (handlers == null || handlers.size() == 0) {
return false;
}
for (ResolveInfo resolveInfo : handlers) {
IntentFilter filter = resolveInfo.filter;
if (filter == null) continue;
if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
if (resolveInfo.activityInfo == null) continue;
return true;
}
} catch (RuntimeException e) {
Log.e(TAG, "Runtime exception while getting specialized handlers");
}
return false;
}
示例9: hasSpecializedHandlerIntents
import android.content.IntentFilter; //导入依赖的package包/类
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
try {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> handlers = pm.queryIntentActivities(
intent,
PackageManager.GET_RESOLVED_FILTER);
if (handlers == null || handlers.size() == 0) {
return false;
}
for (ResolveInfo resolveInfo : handlers) {
IntentFilter filter = resolveInfo.filter;
if (filter == null) continue;
if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
if (resolveInfo.activityInfo == null) continue;
return true;
}
} catch (RuntimeException e) {
Log.e("Error", "Runtime exception while getting specialized handlers");
}
return false;
}
示例10: registerReceiver
import android.content.IntentFilter; //导入依赖的package包/类
private void registerReceiver() {
if (mRegisteredTimeZoneReceiver) {
return;
}
mRegisteredTimeZoneReceiver = true;
IntentFilter filter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
DigitalWatchFaceService.this.registerReceiver(mTimeZoneReceiver, filter);
}
示例11: onStart
import android.content.IntentFilter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onStart() {
super.onStart();
final IntentFilter filter = new IntentFilter();
// Play and pause changes
filter.addAction(MusicPlaybackService.PLAYSTATE_CHANGED);
// Shuffle and repeat changes
filter.addAction(MusicPlaybackService.SHUFFLEMODE_CHANGED);
filter.addAction(MusicPlaybackService.REPEATMODE_CHANGED);
// Track changes
filter.addAction(MusicPlaybackService.META_CHANGED);
// Player prepared
filter.addAction(MusicPlaybackService.PREPARED);
// Update a list, probably the playlist fragment's
filter.addAction(MusicPlaybackService.REFRESH);
getActivity().registerReceiver(mPlaybackStatus, filter);
// Refresh the current time
final long next = refreshCurrentTime();
queueNextRefresh(next);
MusicUtils.notifyForegroundStateChanged(getActivity(), isPlaying());
}
示例12: onCreate
import android.content.IntentFilter; //导入依赖的package包/类
public void onCreate(Bundle bundle){
super.onCreate(bundle);
mUpdateReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
if(intent!=null&& ArchosMediaIntent.ACTION_VIDEO_SCANNER_SCAN_FINISHED.equals(intent.getAction())) {
getLoaderManager().restartLoader(LOADER_ID_LAST_ADDED, null, MainFragment.this);
Log.d(TAG, "manual reload");
}
}
};
mUpdateFilter = new IntentFilter();
for(String scheme : UriUtils.sIndexableSchemes){
mUpdateFilter.addDataScheme(scheme);
}
mUpdateFilter.addAction(ArchosMediaIntent.ACTION_VIDEO_SCANNER_SCAN_FINISHED);
}
示例13: registerReceiver
import android.content.IntentFilter; //导入依赖的package包/类
/** 注册广播接受来自keyboard的车牌号 */
public void registerReceiver() {
// 输入车牌完成后的intent过滤器
IntentFilter finishFilter = new IntentFilter(INPUT_LICENSE_COMPLETE);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String license = intent.getStringExtra(INPUT_LICENSE_KEY);
if (license != null && license.length() > 0) {
if (keyboardUtil != null) {
keyboardUtil.hideKeyboard();
}
KeyBoardPopWindow.this.dismiss();
mListener.setLicense(license);
}
}
};
mContext.registerReceiver(receiver, finishFilter);
}
示例14: onCreate
import android.content.IntentFilter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_default).setOnClickListener(this);
findViewById(R.id.btn_custom).setOnClickListener(this);
findViewById(R.id.btn_demo).setOnClickListener(this);
mLlRemoteViewsContainer = (LinearLayout) findViewById(R.id.ll_remote_views);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
IntentFilter intentFilter = new IntentFilter(DemoActivity.ACTION_REMOTE_VIEWS);
registerReceiver(mBroadcastReceiver, intentFilter);
}
示例15: btA2dpConnect
import android.content.IntentFilter; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@RpcMinSdk(Build.VERSION_CODES.KITKAT)
@Rpc(
description =
"Connects to a paired or discovered device with A2DP profile."
+ "If a device has been discovered but not paired, this will pair it."
)
public void btA2dpConnect(String deviceAddress) throws Throwable {
BluetoothDevice device = BluetoothAdapterSnippet.getKnownDeviceByAddress(deviceAddress);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
mContext.registerReceiver(new PairingBroadcastReceiver(mContext), filter);
Utils.invokeByReflection(sA2dpProfile, "connect", device);
if (!Utils.waitUntil(
() -> sA2dpProfile.getConnectionState(device) == BluetoothA2dp.STATE_CONNECTED,
120)) {
throw new BluetoothA2dpSnippetException(
"Failed to connect to device "
+ device.getName()
+ "|"
+ device.getAddress()
+ " with A2DP profile within 2min.");
}
}