跳不同系统界面的方法

作者: wxyass 分类: Android 发布时间: 2017-04-12 17:16

跳不同系统界面的方法

代码:

// 若系统GPS模块没打开, 跳到app应用详情
public static void getAppDetailSettingIntent(Context context) {
    Intent localIntent = new Intent();
    localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (Build.VERSION.SDK_INT >= 9) {
        localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
    } else if (Build.VERSION.SDK_INT <= 8) {
        localIntent.setAction(Intent.ACTION_VIEW);
        localIntent.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");
        localIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
    }
    context.startActivity(localIntent);
}

// 方法失败 因为这事查看注册文件有没有 判断是否有android.permission.ACCESS_FINE_LOCATION权限
private void isHavepermission(){
    PackageManager pm = getPackageManager();  
    boolean permission = (PackageManager.PERMISSION_GRANTED == 
            pm.checkPermission("android.permission.ACCESS_FINE_LOCATION", "et.tsingtaopad"));  
    if (permission) {  
        Toast.makeText(getApplicationContext(), "有这个权限", 0).show(); 
    }else {  
        Toast.makeText(getApplicationContext(), "木有这个权限", 0).show(); 
    } 
}

// 若系统GPS模块没打开, 跳到安全界面
private void openDingWei(){
    ComponentName cm = new ComponentName("com.android.settings",
            "com.android.settings.SecuritySettings");
    Intent intent = new Intent();
    intent.setComponent(cm);
    intent.setAction("android.intent.action.VIEW");
    startActivity(intent);
}

// 弹窗: 手动开启系统GPS定位模块
private void initGPS() {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    // 判断GPS模块是否开启,如果没有则开启
    if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
        Toast.makeText(ShopVisitActivity.this, "请打开GPS",Toast.LENGTH_SHORT).show();
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setMessage("请打开GPS");
        dialog.setPositiveButton("确定",
                    new android.content.DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {

                            // 转到手机设置界面,用户设置GPS
                        Intent intent = new Intent(
                                Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivityForResult(intent, 0); // 设置完成后返回到原来的界面

                        }
                    });
            dialog.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                arg0.dismiss();
            }
        } );
        dialog.show();
    } else {
        // 弹出Toast
//          Toast.makeText(TrainDetailsActivity.this, "GPS is ready",
//                  Toast.LENGTH_LONG).show();
//          // 弹出对话框
//          new AlertDialog.Builder(this).setMessage("GPS is ready")
//                  .setPositiveButton("OK", null).show();
    }
}  

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注