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


Java PermissionChecker.checkSelfPermission方法代碼示例

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


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

示例1: checkPermission

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
public boolean checkPermission(Context context, String... permission) {

        boolean nr = true;

        for (int i = 0; i < permission.length; i++) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                // targetSdkVersion >= Android M, we can
                // use Context#checkSelfPermission
                nr = context.checkSelfPermission(permission[i])
                        == PackageManager.PERMISSION_GRANTED;
            } else {
                // targetSdkVersion < Android M, we have to use PermissionChecker
                nr = PermissionChecker.checkSelfPermission(context, permission[i])
                        == PermissionChecker.PERMISSION_GRANTED;
            }

            if (!nr) {
                break;
            }
        }
        return nr;
    }
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:23,代碼來源:PermissionManager.java

示例2: onRequestPermissionsResult

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
開發者ID:CodyyAndroid,項目名稱:RxPermissions,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例3: checkPermission

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
/**
 * 請求單個權限
 *
 * @param activity   Activity
 * @param permission 權限
 * @param rationale  提示
 */
public void checkPermission(final Activity activity, final String permission, String rationale) {
    if (PermissionChecker.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
        mActivity = activity;
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
            BaseDialog.create(activity)
                    .setTitle(DESC_TITLE)
                    .setContent(rationale)
                    .setPositive(new BaseDialog.OnClickListener() {
                        @Override
                        public void onClick(BaseDialog dialog) {
                            ActivityCompat.requestPermissions(mActivity, new String[]{permission}, REQUEST_CODE);
                        }
                    })
                    .show();
        } else {
            ActivityCompat.requestPermissions(activity, new String[]{permission}, REQUEST_CODE);
        }
    } else {
        if (mOnGrantedListener != null) mOnGrantedListener.onGranted();
    }
}
 
開發者ID:DongYuHui,項目名稱:android_daily_record,代碼行數:29,代碼來源:PermissionUtil.java

示例4: hasSelfPermissions

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
/**
 * Returns true if <code>Activity</code> or <code>Fragment</code> has access to all given permissions.
 *
 * @param context     context
 * @param permissions permissions
 * @return returns true if <code>Activity</code> or <code>Fragment</code> has access to all given permissions.
 */
@TargetApi(value = Build.VERSION_CODES.M)
public static boolean hasSelfPermissions(Context context, String... permissions) {
    if (permissions == null || permissions.length == 0) {
        return false;
    }

    for (String permission : permissions) {
        if (permission.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
            if (!canDrawOverlays(context)) {
                return false;
            }
        } else if (permission.equals(Manifest.permission.WRITE_SETTINGS)) {
            if (!canWriteSetting(context)) {
                return false;
            }
        } else if (PermissionChecker.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
開發者ID:HujiangTechnology,項目名稱:android_library_permissiondispatcher,代碼行數:29,代碼來源:PermissionUtils.java

示例5: createFloatingWindow

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
private void createFloatingWindow() {
    //檢查權限,低於6.0
    int p = PermissionChecker.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);
    if (p == PermissionChecker.PERMISSION_DENIED) {
        Toast.makeText(this, "缺少懸浮窗權限,請配置權限", Toast.LENGTH_SHORT).show();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, 0);
        }
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //大於6.0
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                startActivity(intent);
            } else {
                floatingWindow = new FloatingWindow(this);
            }

        } else {
            floatingWindow = new FloatingWindow(this);
        }

    }

}
 
開發者ID:cjh1005221032,項目名稱:FloatingWindow,代碼行數:27,代碼來源:MainActivity.java

示例6: onClick

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
@Override
public void onClick(View view) {

    mLastSelectedButtonId = view.getId();

    if (R.id.radioExternalShare == mRadioGroup.getCheckedRadioButtonId()) {

        if (PackageManager.PERMISSION_GRANTED != PermissionChecker.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            // パーミッション許可ない場合はRuntimePermissionを要求して処理終了
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_RUNTIME_PERMISSION);
            return;
        }
    }

    // 読み書き実行
    readOrWrite();
}
 
開發者ID:yokmama,項目名稱:honki_android2,代碼行數:19,代碼來源:MainActivity.java

示例7: checkSelfPermission

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
/**
 * 檢查權限授權狀態
 *
 * @param context
 * @param permission
 * @return
 */
int checkSelfPermission(Context context, String permission) {
    try {
        final PackageInfo info = context.getPackageManager().getPackageInfo(
                context.getPackageName(), 0);
        int targetSdkVersion = info.applicationInfo.targetSdkVersion;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (targetSdkVersion >= Build.VERSION_CODES.M) {
                Log.i(TAG, "targetSdkVersion >= Build.VERSION_CODES.M");
                return ContextCompat.checkSelfPermission(context, permission);
            } else {
                return PermissionChecker.checkSelfPermission(context, permission);
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return ContextCompat.checkSelfPermission(context, permission);
}
 
開發者ID:smuyyh,項目名稱:SprintNBA,代碼行數:26,代碼來源:AcpService.java

示例8: checkPermissionCamera

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
private void checkPermissionCamera() {
    int checkPermission = 0;
    if (Build.VERSION.SDK_INT >= 23) {
        // checkPermission =ContextCompat.checkSelfPermission(this,Manifest.permission.CAMERA);
        checkPermission = PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (checkPermission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    MY_PERMISSIONS_REQUEST_CAMERA);
        } else {
            isOpenCamera = true;
        }

    } else {
        checkPermission = checkPermission(26);
        if (checkPermission == AppOpsManager.MODE_ALLOWED) {
            isOpenCamera = true;
        } else if (checkPermission == AppOpsManager.MODE_IGNORED) {
            isOpenCamera = false;
            displayFrameworkBugMessageAndExit();
        }
    }
}
 
開發者ID:zybieku,項目名稱:ZbarCode,代碼行數:24,代碼來源:CaptureActivity.java

示例9: onCreate

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);

    setResult(RESULT_CANCELED);

    if (Build.VERSION.SDK_INT >= 23 && PermissionChecker
            .checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
            PermissionChecker.PERMISSION_GRANTED && PermissionChecker
            .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
            PermissionChecker.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE_PERMISSION);
    } else {
        start();
    }
}
 
開發者ID:j4velin,項目名稱:PictureChooser,代碼行數:18,代碼來源:Main.java

示例10: onCreate

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (PermissionChecker
            .checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
            PermissionChecker.PERMISSION_GRANTED || PermissionChecker
            .checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
            PermissionChecker.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(Map.this,
                new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
                        Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSIONS);
    } else {
        showMap();
    }
}
 
開發者ID:j4velin,項目名稱:WiFi-Automatic,代碼行數:17,代碼來源:Map.java

示例11: onARSwitchButtonClicked

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
public void onARSwitchButtonClicked(View v) {
    if( button_AR.isChecked() == true ) { // OFF → ONのとき

        // パーミッションを持っているか確認する
        if (PermissionChecker.checkSelfPermission(
                RaderActivity.this, Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            // パーミッションをリクエストする
            permissionManager.requestCameraPermission();
            return;
        }
        Log.d( "REQUEST PERMISSION", "パーミッション取得済み" );
        // ARモード開始
        startARMode();
    }
    else { // ON → OFFのとき
        // ARモード終了
        RADER_VALUES.switchARMode( false );
        // カメラ開放
        mCamera.close();
        mCamera = null;
        // 背景差し替え(imageView表示)
        backgroundImageView.setVisibility( backgroundImageView.VISIBLE );
        // AR用メッセージ非表示
        linearLayout_ARMessages.setVisibility( View.GONE );
        // レーダー用メッセージ表示
        linearLayout_raderMessages.setVisibility( View.VISIBLE );
    }
}
 
開發者ID:jphacks,項目名稱:TK_1701,代碼行數:30,代碼來源:RaderActivity.java

示例12: hasPermission

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
/**
 * 判斷權限是否授權
 * @param context
 * @param permissions
 * @return
 */
public static boolean hasPermission(@NonNull Context context, @NonNull String... permissions) {
    for (String per : permissions ) {
        int result = PermissionChecker.checkSelfPermission(context, per);
        if ( result != PermissionChecker.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:16,代碼來源:PermissionsUtil.java

示例13: onCreate

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker
            .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
            PermissionChecker.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
    }

    phHueSDK.setAppName("HueNotifier");
    phHueSDK.setDeviceName(android.os.Build.MODEL);
    phHueSDK.getNotificationManager().registerSDKListener(listener);

    connectToBridge();

    Database db = Database.getInstance(this);
    rules = db.getRules();
    db.close();

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            addRule();
        }
    });

    ruleList = (RecyclerView) findViewById(R.id.list);
    ruleList.setHasFixedSize(false);
    ruleList.setLayoutManager(
            new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    ruleAdapter = new RuleAdapter(this);
    ruleList.setAdapter(ruleAdapter);
}
 
開發者ID:j4velin,項目名稱:HueNotifier,代碼行數:38,代碼來源:MainActivity.java

示例14: getLastKnownLocation

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
private Location getLastKnownLocation() {
    Location coarseLoc = null;
    Location fineLoc = null;
    if (PermissionChecker.checkSelfPermission(this.mContext, "android.permission.ACCESS_COARSE_LOCATION") == 0) {
        coarseLoc = getLastKnownLocationForProvider("network");
    }
    if (PermissionChecker.checkSelfPermission(this.mContext, "android.permission.ACCESS_FINE_LOCATION") == 0) {
        fineLoc = getLastKnownLocationForProvider("gps");
    }
    return (fineLoc == null || coarseLoc == null) ? fineLoc == null ? coarseLoc : fineLoc : fineLoc.getTime() > coarseLoc.getTime() ? fineLoc : coarseLoc;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:12,代碼來源:TwilightManager.java

示例15: checkSelfPermission

import android.support.v4.content.PermissionChecker; //導入方法依賴的package包/類
public boolean checkSelfPermission(Context context, String permission)
{
	// For Android < Android Marshmallow(23), self permissions are always granted.
	boolean result = true;

	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
	{
		// https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
		int targetSdkVersion = Build.VERSION_CODES.BASE;
		try
		{
			final PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
			targetSdkVersion = info.applicationInfo.targetSdkVersion;
		}
		catch(PackageManager.NameNotFoundException e)
		{
			e.printStackTrace();
		}

		if(targetSdkVersion >= Build.VERSION_CODES.M)
		{
			// targetSdkVersion >= Android M, we can use Context#checkSelfPermission
			result = context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
		}
		else
		{
			// targetSdkVersion < Android M, we have to use PermissionChecker
			result = PermissionChecker.checkSelfPermission(context,
					permission) == PermissionChecker.PERMISSION_GRANTED;
		}
	}

	return result;
}
 
開發者ID:KAlO2,項目名稱:PerfectShow,代碼行數:35,代碼來源:BaseActivity.java


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