簡體   English   中英

Android:如何制作默認的撥號器應用程序?

[英]Android: How to make a default dialer app?

今天,我的應用程式Facetocall遭到 Google拒絕

  • 您的應用似乎沒有提示用戶在根據策略要求請求相關權限之前是默認處理程序。 請進行必要的更改,以符合政策要求,然后通過聲明表單重新提交您的應用。

  • 聲明表單上列出了默認處理程序功能,但您的應用沒有默認處理程序功能。

我的目標是制作一個默認的撥號程序。

這是我的清單

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.gazman.beep"
    android:installLocation="preferExternal">

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.WRITE_CALL_LOG" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    ... and other permissions

    <application
        android:name=".application.BeepApp"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        tools:ignore="GoogleAppIndexingWarning">

        <activity
            android:name=".system_intents.IntentsActivity"
            android:launchMode="singleTask"
            android:noHistory="true"
            android:theme="@style/Theme.Transparent">
            <intent-filter>
                <action android:name="android.intent.action.DIAL" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.DIAL" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="tel" />
            </intent-filter>
        </activity>

        <activity
            android:name=".call.CallActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:showForAllUsers="true" />

        <service
            android:name="com.gazman.beep.call.MyInCallService"
            android:permission="android.permission.BIND_INCALL_SERVICE">
            <meta-data
                android:name="android.telecom.IN_CALL_SERVICE_UI"
                android:value="true" />
            <intent-filter>
                <action android:name="android.telecom.InCallService" />
            </intent-filter>
        </service>

        ... And other declarations

    </application>

</manifest>

這是我的應用啟動時的操作:

private void checkDefaultHandler() {
    if (isAlreadyDefaultDialer()) {
        return;
    }
    Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
    intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
    }
    else{
        throw new RuntimeException("Default phone functionality not found");
    }
}

private boolean isAlreadyDefaultDialer() {
    TelecomManager telecomManager = (TelecomManager) getSystemService(TELECOM_SERVICE);
    return getPackageName().equals(telecomManager.getDefaultDialerPackage());
}

我在這里想念什么?

我嘗試再次提交表單,這次我添加了一個在模擬器上顯示我的應用的視頻 (我在所有實際設備上也看到相同的行為),這是我得到的答復:

  • 您的應用似乎沒有提示用戶在根據策略要求請求相關權限之前是默認處理程序。 請進行必要的更改,以符合政策要求,然后通過聲明表單重新提交您的應用。

您不必驚慌。 關於我應用程序中AdMob內容的對話也與我發生了。 我完美地聲明了所有內容,但仍然有人說由於我的應用正在顯示的廣告類型,內容分級不高。 當交換了更多郵件時,他們向我發送了帶有錯誤廣告證明的屏幕截圖,因此最終我再次檢查了我的整個代碼,發現了我的錯誤。

這里的意思是Google擅長於他們的工作,如果他們這么說,那么您的應用程序就缺少了一些東西。

老實說,您的應用程序沒有要求用戶在任何地方允許將其設置為默認值,而是在后台將自身設置為默認值。 您應該要求應用程序要求的每一個至關重要的許可,任何應用程序,病毒或間諜軟件都可以使用這些許可來干擾用戶隱私

您可以使用以下示例中的功能來完成該操作,該功能向用戶請求“相機”權限:

private void requestCameraPermission() {
        Log.i(TAG, "CAMERA permission has NOT been granted. Requesting permission.");

        // BEGIN_INCLUDE(camera_permission_request)
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CAMERA)) {
            // Provide an additional rationale to the user if the permission was not granted
            // and the user would benefit from additional context for the use of the permission.
            // For example if the user has previously denied the permission.
            Log.i(TAG,
                    "Displaying camera permission rationale to provide additional context.");
            Snackbar.make(mLayout, R.string.permission_camera_rationale,
                    Snackbar.LENGTH_INDEFINITE)
                    .setAction(R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ActivityCompat.requestPermissions(MainActivity.this,
                                    new String[]{Manifest.permission.CAMERA},
                                    REQUEST_CAMERA);
                        }
                    })
                    .show();
        } else {

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

您可以在Google Samples中查看完整的存儲庫

不用擔心 如果您糾正此問題,他們將像您一樣接受您的申請。

要設置默認的撥號器應用程序,您需要做兩件事:

1.在您的android清單中添加以下權限

<activity>
    <intent-filter>
        <action android:name="android.intent.action.DIAL"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>
  1. 實際執行檢查:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main_layout)
    ...
    checkDefaultDialer()
    ...
}
const val REQUEST_CODE_SET_DEFAULT_DIALER=200

private fun checkDefaultDialer() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return

    val telecomManager = getSystemService(TELECOM_SERVICE) as TelecomManager
    val isAlreadyDefaultDialer = packageName == telecomManager.defaultDialerPackage
    if (isAlreadyDefaultDialer)
        return
    val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
                .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
    startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    when (requestCode) {
        REQUEST_CODE_SET_DEFAULT_DIALER -> checkSetDefaultDialerResult(resultCode)
    }
}

private fun checkSetDefaultDialerResult(resultCode: Int) {
    val message = when (resultCode) {
        RESULT_OK       -> "User accepted request to become default dialer"
        RESULT_CANCELED -> "User declined request to become default dialer"
        else            -> "Unexpected result code $resultCode"
    }

    Toast.makeText(this, message, Toast.LENGTH_SHORT).show()

}

萬一有人越過這個職位。 我用它來詢問用戶更改默認的戴勒。 知道會有2個窗口提示(對我來說很好)。

   private void setDefaultDialer()


 {
    AlertDialog.Builder builder;
    builder = new AlertDialog.Builder(this);
    builder.setMessage("Do you want to make Cricket your default Dialer?(it will not cover or replace your dialer)")
            .setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    defaultDialerPackage = "cricket";
                    Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
                    startActivityForResult(intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,getPackageName()),REQUEST_CODE_SET_DEFAULT_DIALER);
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    Toast.makeText(getApplicationContext(),"Cancelled - No action was taken",
                            Toast.LENGTH_SHORT).show();
                }
            });

AlertDialog alert = builder.create();
alert.setTitle("Cricket need default dialer permission!!");
alert.show();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM