當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.enforceCallingOrSelfPermission方法代碼示例

本文整理匯總了Java中android.content.Context.enforceCallingOrSelfPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.enforceCallingOrSelfPermission方法的具體用法?Java Context.enforceCallingOrSelfPermission怎麽用?Java Context.enforceCallingOrSelfPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.Context的用法示例。


在下文中一共展示了Context.enforceCallingOrSelfPermission方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReceive

import android.content.Context; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {

    PreferencesProviderWrapper prefWrapper = new PreferencesProviderWrapper(context);
    String intentAction = intent.getAction();

    //
    // ACTION_DATA_STATE_CHANGED
    // Data state change is used to detect changes in the mobile
    // network such as a switch of network type (GPRS, EDGE, 3G)
    // which are not detected by the Connectivity changed broadcast.
    //
    //
    // ACTION_CONNECTIVITY_CHANGED
    // Connectivity change is used to detect changes in the overall
    // data network status as well as a switch between wifi and mobile
    // networks.
    //
    if (/*intentAction.equals(ACTION_DATA_STATE_CHANGED) ||*/
            intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
            intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {
        
        if (prefWrapper.isValidConnectionForIncoming()
                &&
                !prefWrapper
                        .getPreferenceBooleanValue(PreferencesProviderWrapper.HAS_BEEN_QUIT)) {
            Log.d(THIS_FILE, "Try to start service if not already started");
            Intent sip_service_intent = new Intent(context, SipService.class);
            context.startService(sip_service_intent);
        }

    } else if (intentAction.equals(SipManager.INTENT_SIP_ACCOUNT_ACTIVATE)) {
        context.enforceCallingOrSelfPermission(SipManager.PERMISSION_CONFIGURE_SIP, null);

        long accId;
        accId = intent.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID);

        if (accId == SipProfile.INVALID_ID) {
            // allow remote side to send us integers.
            // previous call will warn, but that's fine, no worries
            accId = intent.getIntExtra(SipProfile.FIELD_ID, (int) SipProfile.INVALID_ID);
        }

        if (accId != SipProfile.INVALID_ID) {
            boolean active = intent.getBooleanExtra(SipProfile.FIELD_ACTIVE, true);
            ContentValues cv = new ContentValues();
            cv.put(SipProfile.FIELD_ACTIVE, active);
            int done = context.getContentResolver().update(
                    ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, accId), cv,
                    null, null);
            if (done > 0) {
                if (prefWrapper.isValidConnectionForIncoming()) {
                    Intent sipServiceIntent = new Intent(context, SipService.class);
                    context.startService(sipServiceIntent);
                }
            }
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equalsIgnoreCase(intentAction) ||
            Intent.ACTION_PACKAGE_REMOVED.equalsIgnoreCase(intentAction)) {
        CallHandlerPlugin.clearAvailableCallHandlers();
        RewriterPlugin.clearAvailableRewriters();
        ExtraPlugins.clearDynPlugins();
        PhoneCapabilityTester.deinit();
    } else if (APPLY_NIGHTLY_UPLOAD.equals(intentAction)) {
        NightlyUpdater nu = new NightlyUpdater(context);
        nu.applyUpdate(intent);
    }
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:69,代碼來源:DeviceStateReceiver.java


注:本文中的android.content.Context.enforceCallingOrSelfPermission方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。