app 開發心得

廣告

1. 不要放在 Main Activity,避免拖累開啟速度,影響使用者心情。按下 app 馬上看到程式畫面,是令人心情愉悅的。 譯圖文 工具類的 app 越直接快速越好。可以放在使用者執行完某個動作,需要時間等待時的頁面。

2. 插頁廣告感覺很差,除非你的 app 夠吸引人,能夠讓人無視插頁廣告的不適。
雖然插頁廣告可增加 "點擊率" (誤擊?),可是對少少下載量的 app 還是弊大於利呀。

~ 其他有想到再補充 ~


Android M 以上版本權限取得變更

Google 大神說從 Android M 以上版本的權限取得有改變。

除了以往 mainifests 要求的權限外,在執行時期還要確認使用者是否允許權限使用,

使用者不允許的話還要說明權限需求的原因。

如果 target SDK version 設在 Android 6.0 以上版本要記得使用權限前要實作相應的檢查。



// Identifier for the permission request
private static final int GET_CAMERA_PERMISSIONS_REQUEST = 1;

public void getPermissionToGetCamera() {
    // 1) Use the support library version ContextCompat.checkSelfPermission(...) to avoid
    // checking the build version since Context.checkSelfPermission(...) is only available
    // in Marshmallow
    // 2) Always check for permission (even if permission has already been granted)
    // since the user can revoke permissions at any time through Settings
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {

        // The permission is NOT already granted.
        // Check if the user has been asked about this permission already and denied
        // it. If so, we want to give more explanation about why the permission is needed.

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CAMERA)) {
            // Show our own UI to explain to the user why we need to read the contacts
            // before actually requesting the permission and showing the default UI
            Snackbar.make(mContainer, R.string.permission_camera_rationale,
                    Snackbar.LENGTH_INDEFINITE)
                    .setAction(R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ActivityCompat.requestPermissions(LoadPicModeActivity.this,
                                    new String[]{Manifest.permission.CAMERA},
                                    GET_CAMERA_PERMISSIONS_REQUEST);
                        }
                    })
                    .show();
        } else {

            // Camera permission has not been granted yet. Request it directly.
            ActivityCompat.requestPermissions(LoadPicModeActivity.this, new String[]{Manifest.permission.CAMERA},
                    GET_CAMERA_PERMISSIONS_REQUEST);
        }
    }

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
            == PackageManager.PERMISSION_GRANTED)
    {
        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = Uri.fromFile(Utils.GetTempFile(getApplicationContext(), Global.TEMP_FILE_NAME));
        i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQ);
    }
}

// Callback with the request from calling requestPermissions(...)
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String permissions[],
                                       @NonNull int[] grantResults) {
    // Make sure it's our original READ_CONTACTS request
    if (requestCode == GET_CAMERA_PERMISSIONS_REQUEST) {
        if (grantResults.length == 1 &&
                grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Snackbar.make(mContainer, "Camera permission granted", Snackbar.LENGTH_SHORT).show();
        } else {
            Snackbar.make(mContainer, "Camera permission denied", Snackbar.LENGTH_SHORT).show();
        }
    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

留言

這個網誌中的熱門文章

[IIS] 自我簽署憑證來啟用SSL

相見恨晚的自動化測試開發工具 Sikuli

sqlplus 中文亂碼解決方案