Example usage for android.content IntentFilter setPriority

List of usage examples for android.content IntentFilter setPriority

Introduction

In this page you can find the example usage for android.content IntentFilter setPriority.

Prototype

public final void setPriority(int priority) 

Source Link

Document

Modify priority of this filter.

Usage

From source file:com.oodles.smslistener.SmsListenerModule.java

void setupIntentReceivers() {
    Log.d(LCAT, "inside setupIntentReceivers");
    Activity currentActivity = TiApplication.getInstance().getCurrentActivity();

    //let's register broadcast receivers
    BroadcastReceiver smsReceiver = new BroadcastReceiver() {
        @Override//from w w  w  .  j a va  2 s  .  com
        public void onReceive(Context context, Intent intent) {
            Log.d(LCAT, "inside onReceive");
            KrollDict event;
            switch (getResultCode()) {
            case Activity.RESULT_OK:

                final Bundle bundle = intent.getExtras();
                try {
                    if (bundle != null) {
                        final Object[] pdusObj = (Object[]) bundle.get("pdus");
                        for (int i = 0; i < pdusObj.length; i++) {
                            SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                            String phoneNumber = currentMessage.getDisplayOriginatingAddress();
                            senderNum = phoneNumber;
                            message = currentMessage.getDisplayMessageBody();
                        }
                    }
                } catch (Exception e) {
                    Log.e("SmsReceiver", "Exception smsReceiver" + e);
                }
                event = createEventObject(true, RECEIVED, message, senderNum);
                Log.d(LCAT, "message Received");
                fireEvent("complete", event);
                break;
            default:
                event = createEventObject(false, FAILED, "Message delivery failed", "");
                Log.d(LCAT, "message receiving failure");
                fireEvent("complete", event);
                break;
            }
        }
    };

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.setPriority(1000);
    intentFilter.addAction(MESSAGE_RECEIVED);
    //---when the SMS has been Received---
    currentActivity.registerReceiver(smsReceiver, intentFilter);
}

From source file:org.apache.cordova.plugin.SmsInboxPlugin.java

@Override
public boolean execute(String action, JSONArray arg1, final CallbackContext callbackContext)
        throws JSONException {

    if (action.equals(ACTION_HAS_SMS_POSSIBILITY)) {

        Activity ctx = this.cordova.getActivity();
        if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
        } else {//from  w  ww.jav a  2s.c  o  m
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
        }
        return true;
    } else if (action.equals(ACTION_RECEIVE_SMS)) {

        // if already receiving (this case can happen if the startReception is called
        // several times
        if (this.isReceiving) {
            // close the already opened callback ...
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(false);
            this.callback_receive.sendPluginResult(pluginResult);

            // ... before registering a new one to the sms receiver
        }
        this.isReceiving = true;

        if (this.smsReceiver == null) {
            this.smsReceiver = new SmsReceiver();
            IntentFilter fp = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
            fp.setPriority(1000);
            // fp.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
            this.cordova.getActivity().registerReceiver(this.smsReceiver, fp);
        }

        this.smsReceiver.startReceiving(callbackContext);

        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        this.callback_receive = callbackContext;

        return true;
    } else if (action.equals(ACTION_STOP_RECEIVE_SMS)) {

        if (this.smsReceiver != null) {
            smsReceiver.stopReceiving();
        }

        this.isReceiving = false;

        // 1. Stop the receiving context
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(false);
        this.callback_receive.sendPluginResult(pluginResult);

        // 2. Send result for the current context
        pluginResult = new PluginResult(PluginResult.Status.OK);
        callbackContext.sendPluginResult(pluginResult);

        return true;
    }

    return false;
}

From source file:com.oprisnik.semdroid.AnalysisResultsListFragment.java

@Override
public void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter(AnalysisIntentService.ACTION_ANALYSIS_FINISHED);
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    getActivity().registerReceiver(mAnalysisFinishedReceiver, filter);
}

From source file:org.apache.cordova.smsreceiver.SmsReceivingPlugin.java

@Override
public boolean execute(String action, JSONArray arg1, final CallbackContext callbackContext)
        throws JSONException {

    if (action.equals(ACTION_HAS_RECEIVE_PERMISSION)) {

        Activity ctx = this.cordova.getActivity();
        if (Build.VERSION.SDK_INT >= 23) {

            if (PermissionHelper.hasPermission(this, Manifest.permission.RECEIVE_SMS)) {
                if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
                } else {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
                }/*from  w  w  w  .j ava2 s.co  m*/
                return true;
            } else {
                PermissionHelper.requestPermission(this, 0, Manifest.permission.RECEIVE_SMS);
                JSONObject returnObj = new JSONObject();
                addProperty(returnObj, "permissionGranted", true);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, returnObj));
                return true;
            }
        } else {
            if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
            } else {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
            }
            return true;
        }

    } else if (action.equals(ACTION_START_RECEIVE_SMS)) {

        // if already receiving (this case can happen if the startReception is called
        // several times
        if (this.isReceiving) {
            // close the already opened callback ...
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(false);
            this.callback_receive.sendPluginResult(pluginResult);

            // ... before registering a new one to the sms receiver
        }
        this.isReceiving = true;

        if (this.smsReceiver == null) {
            this.smsReceiver = new SmsReceiver();
            IntentFilter fp = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
            fp.setPriority(1000);
            // fp.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
            this.cordova.getActivity().registerReceiver(this.smsReceiver, fp);
        }

        this.smsReceiver.startReceiving(callbackContext);

        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        this.callback_receive = callbackContext;

        return true;
    } else if (action.equals(ACTION_STOP_RECEIVE_SMS)) {

        if (this.smsReceiver != null) {
            smsReceiver.stopReceiving();
        }

        this.isReceiving = false;

        // 1. Stop the receiving context
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(false);
        this.callback_receive.sendPluginResult(pluginResult);

        // 2. Send result for the current context
        pluginResult = new PluginResult(PluginResult.Status.OK);
        callbackContext.sendPluginResult(pluginResult);

        return true;
    }

    return false;
}

From source file:com.tapchatapp.android.app.activity.BuffersActivity.java

@Override
public void onStart() {
    super.onStart();

    IntentFilter pushFilter = new IntentFilter(TapchatApp.ACTION_MESSAGE_NOTIFY);
    pushFilter.setPriority(10);
    registerReceiver(mPushReceiver, pushFilter);

    IntentFilter openFilter = new IntentFilter(TapchatApp.ACTION_OPEN_BUFFER);
    openFilter.setPriority(10);/*from   w  w  w .j a v  a  2 s.  c om*/
    registerReceiver(mOpenReceiver, openFilter);
}

From source file:com.wenwen.chatuidemo.activity.HomeFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    DebugLog.i(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    // ?BroadcastReceiver
    msgReceiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    intentFilter.setPriority(3);
    getActivity().registerReceiver(msgReceiver, intentFilter);
}

From source file:wanthavers.mad.cs.fau.de.wanthavers_android.desirelist.DesireListActivity.java

@Override
protected void onStart() {
    super.onStart();

    IntentFilter filter = new IntentFilter("WH_PUSH_NOTIFICATION_BROADCAST");
    filter.setPriority(10);

    registerReceiver(notificationReceiver, filter);
}

From source file:com.raspi.chatapp.ui.chatting.ChatListFragment.java

@Override
public void onResume() {
    super.onResume();
    // init ui and register the receiver
    initUI();/* ww  w .jav  a2s.  c  om*/
    IntentFilter filter = new IntentFilter(Constants.MESSAGE_RECEIVED);
    filter.setPriority(1);
    getContext().registerReceiver(messageReceiver, filter);
}

From source file:org.digitalcampus.oppia.service.DownloadService.java

@Override
public void onCreate() {
    super.onCreate();
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    DownloadService.setInstance(this);

    alternativeNotifier = new BroadcastReceiver() {
        @Override/*  w  ww .ja  v  a2s.c  om*/
        public void onReceive(Context context, Intent intent) {
            if (!intent.hasExtra(DownloadService.SERVICE_URL)
                    || !intent.hasExtra(DownloadService.SERVICE_ACTION)) {
                //If the file URL and the action are not present, we can't identify it
                return;
            }
            String fileUrl = intent.getStringExtra(DownloadService.SERVICE_URL);
            String action = intent.getStringExtra(DownloadService.SERVICE_ACTION);
            DownloadService.this.notifyDownloads(action, fileUrl);
        }
    };

    //We register the alternative notifier for sending notifications when no other BroadcasReceiver is set
    IntentFilter broadcastFilter = new IntentFilter(DownloadService.BROADCAST_ACTION);
    broadcastFilter.setPriority(IntentFilter.SYSTEM_LOW_PRIORITY);
    registerReceiver(alternativeNotifier, broadcastFilter);

}

From source file:com.wenwen.chatuidemo.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        // T??home???appcrash
        // fragment??
        finish();/* w ww.j av  a  2 s. c  o  m*/
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.activity_main);
    initView();
    UmengUpdateAgent.update(this); // wifi??
    MobclickAgent.setDebugMode(true);
    MobclickAgent.updateOnlineConfig(this);
    homeFragment = new HomeFragment();
    newFragment = new NewFragment();
    contactSickFragment = new ContactSickFragment();
    contactListFragment = new ContactlistFragment();
    settingFragment = new PersonFragment();
    fragments = new Fragment[] { homeFragment, contactListFragment, contactSickFragment, newFragment,
            settingFragment };
    // fragment
    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, homeFragment).show(homeFragment)
            .commit();
    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(3);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);
    // ??BroadcastReceiver
    IntentFilter cmdMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getCmdMessageBroadcastAction());
    cmdMessageIntentFilter.setPriority(3);
    registerReceiver(cmdMessageReceiver, cmdMessageIntentFilter);
    // sdkUI ??receiverlistener, ??broadcast
    EMChat.getInstance().setAppInited();
}