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:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

/**
 * Register an SMS Data (Binary) Receiver
 *//*from w  w  w. j  a va  2s  . co m*/
private void registerSmsReceiver() {
    smsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Debug.i("Received Binary SMS");

            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;

            if (null != bundle) {
                // In telecommunications the term (PDU) means protocol data
                // unit.
                // There are two ways of sending and receiving SMS messages:
                // by text mode and by PDU (protocol description unit) mode.
                // The PDU string contains not only the message, but also a
                // lot of meta-information about the sender, his SMS service
                // center, the time stamp etc
                // It is all in the form of hexa-decimal octets or decimal
                // semi-octets.
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];

                for (int i = 0; i < msgs.length; i++) {
                    // Create the Message
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    // Get Message Parameters
                    SmsObject receivedSms = new SmsObject();
                    receivedSms.setTelephoneNumber(msgs[i].getOriginatingAddress());
                    receivedSms.setMessageTimestamp(msgs[i].getTimestampMillis());
                    receivedSms.setMessageData(Base64.encodeToString(msgs[i].getUserData(), Base64.CRLF));

                    Debug.d("Received SMS and it's content hash is: " + BinaryHelpers
                            .toHexadecimealString(Hashing.getMD5Hash(msgs[i].getUserData()).toByteArray()));

                    // Store the SmsObject to the db
                    dao.storeSms(receivedSms);
                }
            }

            // This will stop the Broadcast and not allow the message to
            // be interpreted by the default Android app or other apps
            abortBroadcast();
        }
    };

    // Set up the Receiver Parameters
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.setPriority(999);
    mIntentFilter.addAction("android.intent.action.DATA_SMS_RECEIVED");
    mIntentFilter.addDataScheme("sms");
    // Set the Port that is listening to
    mIntentFilter.addDataAuthority("*", "2013");
    // mIntentFilter.addDataType(type)
    registerReceiver(smsReceiver, mIntentFilter);
    Debug.d("Set up BinarySMS receiver.");
}

From source file:org.digitalcampus.oppia.activity.DownloadActivity.java

@Override
public void onResume() {
    super.onResume();
    if (json == null) {
        //The JSON download task has not started or been completed yet
        getCourseList();//from   w  w  w.j a  v  a 2s  . c om
    } else if ((courses != null) && courses.size() > 0) {
        //We already have loaded JSON and courses (coming from orientationchange)
        dla.notifyDataSetChanged();
    } else {
        //The JSON is downloaded but course list is not
        refreshCourseList();
    }
    receiver = new InstallerBroadcastReceiver();
    receiver.setCourseInstallerListener(this);
    IntentFilter broadcastFilter = new IntentFilter(CourseIntallerService.BROADCAST_ACTION);
    broadcastFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    registerReceiver(receiver, broadcastFilter);

}

From source file:net.helff.wificonnector.WifiConnectivityService.java

protected LoginToken waitForToken() throws ConnectionWorkflowException {

    LoginToken loginToken = new LoginToken();

    // set up broadcast receiver
    publishProgress(getString(R.string.wifi_submit_msisdn), getString(R.string.wifi_wait_token), STATUS_WORKING,
            true);/*from  w w w . ja va 2  s.co  m*/
    SMSReceiver receiver = new SMSReceiver(loginToken);
    IntentFilter intentFilter = new IntentFilter(SMSReceiver.ACTION);
    intentFilter.setPriority(smsPriority);
    registerReceiver(receiver, intentFilter);

    int iterations = 1;
    // loop every 500ms and wait for SMS arriving
    while (iterations < (smsDelay * 2) && !loginToken.isTokenSet()) {

        // just wait, therefore sleep a half second
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // just finish then
            break;
        }

        iterations++;
    }

    // remove broadcast receiver
    unregisterReceiver(receiver);

    if (loginToken.isTokenSet()) {
        publishProgress(getString(R.string.wifi_submit_msisdn),
                getString(R.string.wifi_received_token, loginToken.getToken()), STATUS_WORKING);
    } else {
        publishProgress(getString(R.string.wifi_submit_msisdn), getString(R.string.wifi_no_token),
                STATUS_LOCKED, true);
        throw new ConnectionWorkflowException("no token received within 15 seconds");
    }

    return loginToken;
}

From source file:com.kakao.auth.authorization.authcode.KakaoWebViewDialog.java

private void registerSmsReceiverIfNeeded() {
    if (!useSmsReceiver) {
        return;//from   w  w  w  .ja  v  a  2  s . c  o m
    }

    if (smsReceiver != null) {
        return;
    }
    Logger.d("registerSmsReceiver");

    smsReceiver = new SmsReceiver(new ISmsReceiver() {
        @Override
        public void onCompleteSms(String code) {
            Logger.d("++ onCompleteSms(%s)", code);
            if (!TextUtils.isEmpty(code)) {
                final String url = String.format(Locale.US, "javascript:insertSms('%s')", code);
                Logger.d("++ command : " + url);
                webView.loadUrl(url);
            }
        }
    });

    IntentFilter filter = new IntentFilter();
    filter.addAction(SmsReceiver.ACTION);
    filter.setPriority(999); // ? SMS  ?? SMS  priority 3  .
    getContext().getApplicationContext().registerReceiver(smsReceiver, filter);
}

From source file:com.rjfun.cordova.sms.SMSPlugin.java

protected void createIncomingSMSReceiver() {
    Activity ctx = this.cordova.getActivity();
    this.mReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d(LOGTAG, ("onRecieve: " + action));
            if (SMS_RECEIVED.equals(action)) {
                Bundle bundle;//from   ww w.java  2  s . c o  m
                if (SMSPlugin.this.mIntercept) {
                    this.abortBroadcast();
                }
                if ((bundle = intent.getExtras()) != null) {
                    Object[] pdus;
                    if ((pdus = (Object[]) bundle.get("pdus")).length != 0) {
                        for (int i = 0; i < pdus.length; ++i) {
                            SmsMessage sms = SmsMessage.createFromPdu((byte[]) ((byte[]) pdus[i]));
                            JSONObject json = SMSPlugin.this.getJsonFromSmsMessage(sms);
                            SMSPlugin.this.onSMSArrive(json);
                        }
                    }
                }
            }
        }
    };
    String[] filterstr = new String[] { SMS_RECEIVED };
    for (int i = 0; i < filterstr.length; ++i) {
        IntentFilter filter = new IntentFilter(filterstr[i]);
        filter.setPriority(100);
        ctx.registerReceiver(this.mReceiver, filter);
        Log.d(LOGTAG, ("broadcast receiver registered for: " + filterstr[i]));
    }
}

From source file:com.xortech.sender.SenderMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sender_main);

    // REMOVE THE TITLE FROM THE ACTIONBAR
    getActionBar().setDisplayShowTitleEnabled(false);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    mapType = preferences.getString("mapType", GMAPS);

    // CHECK FOR "DON'T KEEP ACTIVITIES" IN DEVELOPER OPTIONS
    boolean checkDeveloper = isAlwaysFinishActivitiesOptionEnabled();
    if (checkDeveloper) {
        showDeveloperOptionsScreen();/*from   w w  w. jav  a2s .c o m*/
    }

    /*
     * IF GOOGLE MAPS IS SELECTED AS THE DEFAULT, THEN CHECK TO
     * SEE IF THE USER HAS THE CORRECT VERSION OF GOOGLE PLAY SERVICES
     */
    if (mapType.equals(GMAPS)) {
        // GET GOOGLE PLAY STATUS
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // CHECK IF GOOGLE PLAY SERVICE IS AVAILABLE 
        try {
            if (status != ConnectionResult.SUCCESS) {
                GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
            }
        } catch (Exception e) {
            Log.e("Error: GooglePlayServiceUtil: ", "" + e);
        }
    }

    // REGISTER A BROADCAST RECEIVER
    IntentFilter localIntentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    localIntentFilter.setPriority(2147483646);
    mReceiver = new SmsReceiver();
    registerReceiver(mReceiver, localIntentFilter);

    try {
        // TRY TO LAUNCH APP RATER 
        AppRater.app_launched(this);
    } catch (Exception e) {
        Log.e("Error AppRater: ", "" + e);
    }

    // SET UP THE ACTION BAR
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:org.digitalcampus.oppia.activity.DownloadMediaActivity.java

@Override
public void onResume() {
    super.onResume();
    if ((missingMedia != null) && missingMedia.size() > 0) {
        //We already have loaded media (coming from orientationchange)
        dmla.sortByFilename();//  w ww . ja v  a  2  s. c  om
        isSortByCourse = false;
        dmla.notifyDataSetChanged();
        emptyState.setVisibility(View.GONE);
        downloadViaPCBtn.setVisibility(View.VISIBLE);
    } else {
        emptyState.setVisibility(View.VISIBLE);
        downloadViaPCBtn.setVisibility(View.GONE);
    }
    receiver = new DownloadBroadcastReceiver();
    receiver.setMediaListener(this);
    IntentFilter broadcastFilter = new IntentFilter(DownloadService.BROADCAST_ACTION);
    broadcastFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    registerReceiver(receiver, broadcastFilter);

    invalidateOptionsMenu();
}

From source file:org.digitalcampus.oppia.activity.OppiaMobileActivity.java

@Override
public void onResume() {
    super.onResume();
    this.updateReminders();

    receiver = new InstallerBroadcastReceiver();
    receiver.setCourseInstallerListener(this);
    IntentFilter broadcastFilter = new IntentFilter(CourseIntallerService.BROADCAST_ACTION);
    broadcastFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    registerReceiver(receiver, broadcastFilter);
}

From source file:com.dileepindia.cordova.sms.SMSPlugin.java

protected void createIncomingSMSReceiver() {
    Context ctx = this.cordova.getActivity();

    this.mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d("SMSPlugin", "onRecieve: " + action);

            if ("android.provider.Telephony.SMS_RECEIVED".equals(action)) {
                if (SMSPlugin.this.mIntercept) {
                    abortBroadcast();/*w ww  .  j a  v  a2 s.  co m*/
                }
                Bundle bundle = intent.getExtras();
                if (bundle != null) {
                    Object[] pdus = (Object[]) bundle.get("pdus");
                    if (pdus.length != 0) {
                        for (int i = 0; i < pdus.length; i++) {
                            SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[i]);

                            JSONObject json = SMSPlugin.this.getJsonFromSmsMessage(sms);
                            SMSPlugin.this.onSMSArrive(json);
                        }

                    }
                }
            }
        }
    };
    String[] filterstr = { "android.provider.Telephony.SMS_RECEIVED" };
    for (int i = 0; i < filterstr.length; i++) {
        IntentFilter filter = new IntentFilter(filterstr[i]);
        filter.setPriority(100);
        ctx.registerReceiver(this.mReceiver, filter);
        Log.d("SMSPlugin", "broadcast receiver registered for: " + filterstr[i]);
    }
}

From source file:org.odk.collect.android.activities.InstanceUploaderList.java

@Override
protected void onResume() {
    if (instanceSyncTask != null) {
        instanceSyncTask.setDiskSyncListener(this);
        if (instanceSyncTask.getStatus() == AsyncTask.Status.FINISHED) {
            syncComplete(instanceSyncTask.getStatusMessage());
        }/* w w w .  j  av  a2s. c om*/

    }
    super.onResume();

    IntentFilter filter = new IntentFilter(SmsNotificationReceiver.SMS_NOTIFICATION_ACTION);
    // The default priority is 0. Positive values will be before
    // the default, lower values will be after it.
    filter.setPriority(1);

    registerReceiver(smsForegroundReceiver, filter);
    setupUploadButtons();
}