After the CTA certification, the camera positioning permission is not allowed to be enabled, and a custom pop-up window is added to simulate the system positioning permission, but the actual permission will not be granted after the permission is allowed.

vendor/mediatek/proprietary/packages/apps/Camera2

In fact, it is a simulated system pop-up window, making a custom one. After the user clicks to allow, it will not pop up next time, but the permission is not actually given. After rejecting it, it will pop up next time. The key storage is SharedPreference

process:

host/src/com/mediatek/camera/CameraActivity.java

import android.content.SharedPreferences;

在protectedvoid onCreateTasks(Bundle savedInstanceState) {

join in

if (!isLocationAllow()) {
           Intent permissionIntent = new Intent(Intent.ACTION_VIEW);
           permissionIntent.setClass(this, CtaPermissionActivity.class);
           permissionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                            |Intent.FLAG_ACTIVITY_CLEAR_TOP
                            |Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
           startActivity(permissionIntent);
        }

The methods and variables used

public boolean isLocationAllow() {
       SharedPreferences settings = this.getSharedPreferences(FMRADIO_CONFIRM_PREF_NAME,0);
       return settings.getBoolean(CONFIRM_VALUE_KEY, false);
    }
 
   private final String FMRADIO_CONFIRM_PREF_NAME ="ConfirmPrefFile";
    privatefinal String CONFIRM_VALUE_KEY = "mtk_location_confirmed";

Create an activity file in

host/src/com/mediatek/camera/CtaPermissionActivity.java

    packagecom.mediatek.camera;
     
    importandroid.app.Activity;
    importandroid.os.Bundle;
    importandroid.content.Intent;
    importandroid.util.Log;
    importandroid.content.Context;
    importandroid.app.AlertDialog;
    importandroid.app.Dialog;
    importandroid.content.DialogInterface;
    importandroid.content.SharedPreferences;
    importandroid.widget.Toast;
    importandroid.view.MotionEvent;
    importandroid.graphics.Color;
    importandroid.view.Gravity;
    importandroid.graphics.drawable.ColorDrawable;
     
    publicclass CtaPermissionActivity extends Activity {
     
        private static final String TAG ="CtaPermissionActivity";
        private final StringFMRADIO_CONFIRM_PREF_NAME = "ConfirmPrefFile";
        private final String CONFIRM_VALUE_KEY ="mtk_location_confirmed";
     
        @Override
        protected void onCreate(BundlesavedInstanceState) {
            super.onCreate(savedInstanceState);
           setContentView(R.layout.layout_cat_permission);
            buildAndShowConfirmDialog();
        }
        
        @Override
       public boolean onTouchEvent(MotionEvent event) {
            return false;
        }
        
        private void buildAndShowConfirmDialog() {
            SharedPreferences settings =getSharedPreferences(FMRADIO_CONFIRM_PREF_NAME, 0);
            SharedPreferences.Editor editor =settings.edit();
            if(!settings.getBoolean(CONFIRM_VALUE_KEY, false)) {
                Dialog dialog = newAlertDialog.Builder(this)
                       .setTitle(R.string.confirm_dialog_title)
                       .setMessage(R.string.confirm_dialog_msg)
                       .setPositiveButton(R.string.confirm_dialog_allow_button,
                                newDialogInterface.OnClickListener() {
                                    public voidonClick(DialogInterface dialog, int whichButton) {
                                        editor.putBoolean(CONFIRM_VALUE_KEY,true);
                                       editor.commit();
                                        finish();
                                    }
                                })
                        .setNegativeButton(R.string.confirm_dialog_deny_button,
                                newDialogInterface.OnClickListener() {
                                    public voidonClick(DialogInterface dialog, int whichButton) {
                                        Toast toast =Toast.makeText(getApplicationContext(), R.string.deny_toast_msg,
                                               Toast.LENGTH_LONG);
                                       toast.show();
                                       editor.putBoolean(CONFIRM_VALUE_KEY, false);
                                       editor.commit();
                                        finish();
                                    }
                                })
                        .create();
     
                dialog.setCanceledOnTouchOutside(false);
                dialog.setCancelable(false);
     
                dialog.show();
            }
       }
    }

This activity requires registration

host/AndroidManifest.xml

    <activity
               android:name="com.mediatek.camera.CtaPermissionActivity"
                android:theme="@android:style/Theme.Dialog"
               android:clearTaskOnLaunch="true"
               android:screenOrientation="portrait"
               android:label="@string/camera_label"
               android:launchMode="singleTask">
                <intent-filter>
                    <actionandroid:name="android.intent.action.MAIN" />
                </intent-filter>
            </activity>

The creation of the layout file of this activity is actually empty and nothing, and it just calls the dialog box of the system.

host/res/layout/layout_cat_permission.xml

    <?xmlversion="1.0" encoding="utf-8"?>
    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
     
    </LinearLayout>

The required string is added to the

host/res/values/strings.xml

host/res/values-zh-rCN/strings.xml

    <stringname="confirm_dialog_title">Security warning</string>
        <stringname="confirm_dialog_msg">Camera is trying to obtain your currentposition.</string>
        <stringname="confirm_dialog_allow_button">Allow</string>
        <string name="confirm_dialog_deny_button">Deny</string>
        <stringname="deny_toast_msg">Camera is denied to obtainlocation.</string>
     
    <stringname="confirm_dialog_title">“安全提醒” </string>
        <stringname="confirm_dialog_msg">“相机会尝试取得您的位置资讯以供功能正常运行”</string>
        <string name="confirm_dialog_allow_button">“允许”</string>
        <stringname="confirm_dialog_deny_button">“拒绝”</string>
        <stringname="deny_toast_msg">相机被拒绝用位置资讯</string>

The last step is to set up the manger class of management permissions in the camera, and open the function of asking permissions every time

common/src/com/mediatek/camera/common/permission/PermissionManager.java

Similar to the modification of cameraactivity, it is just for safety, because originally this camera will not give positioning permission. This is just for convenience in the future, if you decide to add permission function, then you need to be here, now no matter whether you allow or deny, there is no function.

There is no need for the following

importandroid.content.SharedPreferences;

in method

publicboolean checkCameraLocationPermissions() {

Join if (!isLocationAllow()) return false;

In method public booleanrequestCameraLocationPermissions() {

add if (!isLocationAllow()) {

return false;

}

Methods and Quantification Required

publicboolean isLocationAllow() {

SharedPreferences settings =mActivity.getSharedPreferences(FMRADIO_CONFIRM_PREF_NAME, 0);

returnsettings.getBoolean(CONFIRM_VALUE_KEY, false);

}

private final StringFMRADIO_CONFIRM_PREF_NAME = "ConfirmPrefFile";

private final String CONFIRM_VALUE_KEY ="mtk_location_confirmed";

key point:

The activity here is copied

@Override

public boolean onTouchEvent(MotionEventevent) {

return false;

}

Just intercept all touch screen events without processing

Storage usage of SharedPreferences

When using the SharedPreferences class to store data, you first need to call the getSharedPreferences (Stringname, int mode) method to get the instance object, open the Preferences, the name is setting, if it exists, open it, otherwise create a new Preferences

SharedPreferencessettings = getSharedPreferences(FMRADIO_CONFIRM_PREF_NAME, 0);

Since the object itself can only obtain data and cannot store and modify data, it is necessary to call the edit() method of SharedPreferences to obtain editable

SharedPreferences.Editor editor = settings.edit();

Then you can pass the value, one key and one value, and finally submit

editor.putBoolean(CONFIRM_VALUE_KEY,true);

editor.commit();

When calling this data with other classes in the application

SharedPreferencessettings = this.getSharedPreferences(FMRADIO_CONFIRM_PREF_NAME, 0);

settings.getBoolean(CONFIRM_VALUE_KEY,false);

In addition, there are two commonly used methods

editor.remove(“name”); //Delete a piece of data

editor.clear(); //Delete all data

Guess you like

Origin blog.csdn.net/youthking1314/article/details/129621209