2016-04-25 8 views
0

こんにちは私はインストールされたアプリケーションのキャッシュをクリアしようとしていますが、私はアンドロイド6.0のバージョンの下でこれを達成しました。 java.lang.SecurityExceptionをスローします:ユーザプロセスも現在のプロセスもandroid.permission.CLEAR_APP_CACHEを持ちません。しかし、mainfest.xmlに定義しました。しかし、私はそれがセキュリティ上の理由からアンドロイド6.0で実行できないことも読んでいますが、Clean Masterのような最も一般的なアプリケーションはキャッシュをクリアします。クリーンなマスタクリアアプリケーションのキャッシュはどのようにするのですか?私を助けてください。私はここで立ち往生している。 〜アンドロイドM(6.0)の他のアプリケーションのキャッシュをプログラムでクリアする方法

+0

こんにちは、私はアンドロイドM(6.0)のキャッシュメモリをクリアするために他のアプリで使用されているハックを持っています。今、私はアンドロイドMのキャッシュメモリをクリアすることができます。返信してくれてありがとう..ありがとうもう一度 –

+0

@jitendarサインはあなたが解決策であったものを共有することができます。 – sector11

+0

@ sector11彼らはそれを行うアクセシビリティサービスを使用しています... –

答えて

1

Android Mの場合、すべての権限はユーザーが付与する必要があります。したがって、manifest.xmlで宣言する必要があります。

以下のリンクをクリックすると、ユーザーがどのように許可を与えることができるかをご案内します。

http://developer.android.com/training/permissions/requesting.html

あなたは、コードの下に追加して、コードを更新する必要があります。

if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CLEAR_APP_CACHE) != PackageManager.PERMISSION_GRANTED) { 
       // TODO: Consider calling 
       // ActivityCompat#requestPermissions 
       // here to request the missing permissions, and then overriding 
       // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
       //           int[] grantResults) 
       // to handle the case where the user grants the permission. See the documentation 
       // for ActivityCompat#requestPermissions for more details. 
       if (ActivityCompat.shouldShowRequestPermissionRationale((IssueItemDetailActivity) mContext, 
         Manifest.permission.CLEAR_APP_CACHE)) { 

        // Show an expanation to the user *asynchronously* -- don't block 
        // this thread waiting for the user's response! After the user 
        // sees the explanation, try again to request the permission. 

        ActivityCompat.requestPermissions(YourActivity.this, 
          new String[]{Manifest.permission.CLEAR_APP_CACHE}, 
          1); 

       } else { 

        // No explanation needed, we can request the permission. 

        ActivityCompat.requestPermissions(YourActivity.this, 
          new String[]{Manifest.permission.CLEAR_APP_CACHE}, 
          1); 

        // 1 is an int constant. The callback method gets the result of the request. 
       } 

       return; 
      } 

次に、以下の方法でオーバーライドします:

@Override 
    public void onRequestPermissionsResult(int requestCode, 
              String permissions[], int[] grantResults) { 
     switch (requestCode) { 
      case 1: { 
       // If request is cancelled, the result arrays are empty. 
       if (grantResults.length > 0 
         && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

        // permission was granted, yay! Do the 

        // contacts-related task you need to do. 


       } else { 

        // permission denied, boo! Disable the 
        // functionality that depends on this permission. 

        Toast.makeText(mContext,"You need to accept the permission",Toast.LENGTH_SHORT).show(); 
       } 
       return; 
      } 

      // other 'case' lines to check for other 
      // permissions this app might request 
     } 
    } 

をそしてmanifest.xmlに、あなたのコードの下に追加します。

<permission android:name="android.permission.CLEAR_APP_CACHE"/> 
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/> 

お手伝い願います。

+1

しかし、彼はまだポイントを持って..どのようにきれいなマスターは、データをクリア..許可を求めることなし.. – Sanoop

+0

私もそれを行います。実行時に許可を要求します。しかし、まだ同じ問題に直面している.. –

+0

@サノップ:私はマシュマロ装置を持っており、それはすべての許可を求める。 – KishuDroid

関連する問題