如何在我的应用程序中删除android.permission.WRITE_EXTERNAL_STORAGE

时间:2019-06-18 08:37:20

标签: java android android-studio

我写了一个要在市场上发布的应用程序。问题是市场要求我删除android.permission.READ_EXTERNAL_STORAGEandroid.permission.WRITE_EXTERNAL_STORAGE

我从清单中删除了这两个额外的权限,但是当我在手机中检查我的应用程序权限时,我可以在权限列表中看到“修改或删除SD卡的内容”。 这个应用程式使用的是SQLite数据库,但我不确定问题是否是因为这个。

我已经在我的应用程序中完全搜索了此权限,但是没有找到任何相关代码!

唯一的一点是该应用程序正在使用以下依赖项: com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1

请指导我

清单:

<?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.ehin.darookhane">

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

    <application
        android:name="com.ehin.darookhane.ApplicationClass"
        android:allowBackup="true"
        android:icon="@mipmap/ic_darookhane"
        android:label="داروخانه همراه"
        android:supportsRtl="false"
        android:theme="@style/AppTheme"
        tools:replace="android:label,android:supportsRtl"
        android:networkSecurityConfig="@xml/network_security_config">

        <activity
            android:name="com.ehin.darookhane.NetworkActivity"
            android:theme="@style/AppTheme"></activity>
        <activity
            android:name=".MTN.SplashActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.ehin.darookhane.ActivityList"
            android:screenOrientation="portrait" />
        <activity
            android:name="com.ehin.darookhane.ActivityContent"
            android:screenOrientation="portrait" />
        <activity
            android:name="com.ehin.darookhane.ActivityFavorite"
            android:screenOrientation="portrait" />



        <activity
            android:name="com.ehin.darookhane.MTN.LoginActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name="com.ehin.darookhane.MTN.IntroActivity"
            android:screenOrientation="portrait" />
        <activity android:name="com.ehin.darookhane.MainActivity"></activity>

        <receiver android:name=".SmsReceiver">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

    </application>


</manifest>

MainActivity:

package com.ehin.darookhane;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.billingclient.util.IabHelper;
import com.android.billingclient.util.IabResult;
import com.android.billingclient.util.Inventory;
import com.android.billingclient.util.MarketIntentFactorySDK;
import com.android.billingclient.util.Purchase;
import com.ehin.darookhane.MTN.LoginActivity;
import com.ehin.darookhane.MTN.SHPManager;
import com.ehin.darookhane.MTN.SplashActivity;
import com.ehin.darookhane.Network.GetDataService;
import com.ehin.darookhane.Network.RetrofitClientInstance;
import com.ehin.darookhane.Retro.TokenModel;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;

import net.jhoobin.amaroidsdk.Amaroid;

import org.apache.http.Header;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class MainActivity extends AppCompatActivity {

    public static Typeface font;
    public static MyDatabase database;
    public static String otpRef, transCode;

    //---mnhpr
    private Activity sp;
    private IabHelper mHelper;
    private String base64EncodedPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChWypDjkvydsbaE9rnD8X0t0iMbcoW8FxAqsy5kC6kttO9Rvrmamzo1NRt44jbS/OIb+F5OUgNcKhxME73zDyRz8FtRG4h5jzmcoXPS7Q2HSCO88GYMbOteJcxp/ctraZdvGVFPrA3mDPRZ+36dGmMpw6dZby3KuGUrfxBr9wcSwIDAQAB";
    boolean isReady = false;
    private GetDataService service;
    AlertDialog.Builder unSubDialog;
    public static boolean userState;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.ehin.darookhane.R.layout.activity_main);


        //----------------------------

        font = Typeface.createFromAsset(getAssets(), "font/iran sans light.ttf");

        Toolbar toolbar = (Toolbar) findViewById(com.ehin.darookhane.R.id.toolbar);
        TextView title_toolbar = (TextView) findViewById(com.ehin.darookhane.R.id.title_toolbar);
        TextView txt_list = (TextView) findViewById(com.ehin.darookhane.R.id.txt_list);
        TextView txt_favorite = (TextView) findViewById(com.ehin.darookhane.R.id.txt_favorite);
        TextView txt_rate = (TextView) findViewById(com.ehin.darookhane.R.id.txt_rate);
        CardView card_list = (CardView) findViewById(com.ehin.darookhane.R.id.card_list);
        CardView card_favorite = (CardView) findViewById(com.ehin.darookhane.R.id.card_favorite);
        CardView card_rate = (CardView) findViewById(com.ehin.darookhane.R.id.card_rate);
        ImageView img_more = (ImageView) findViewById(com.ehin.darookhane.R.id.img_menu_more);


//----------
        sp = this;
        SHPManager.getInstance().SetToken(SHPManager.getInstance().GetToken());//todo inja token bzar
        Log.e("tokentoken", SHPManager.getInstance().GetToken() + "token");


        //Amaroid
        Amaroid.getInstance().setTags("tagCmpOne", null, null);
        Amaroid.getInstance().submitEventPageView(this, "MainActivity");

        service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class);


        if (!SHPManager.getInstance().GetToken().equals("Hamrah1")) {


            if (!Boolean.parseBoolean(getPreferencesS("userState", getApplicationContext()))) {
                Intent intent = new Intent(this, LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
                return;
            } else {
                userState = true;
            }


            PackageInfo packageInfo = null;
            long versionCode = 0;
            try {
                packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                //    versionCode = PackageInfoCompat.getLongVersionCode(packageInfo);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                //Amaroid
                Amaroid.getInstance().submitEventException(this, e);
            }

            mHelper = new IabHelper(this, base64EncodedPublicKey, new MarketIntentFactorySDK(true));

            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                public void onIabSetupFinished(IabResult result) {
                    Log.d(TAG, "Setup finished.");
                    if (!result.isSuccess()) {
                        return;
                    }
                    if (mHelper == null) return;
                    isReady = true;
                    checkMtnSub(false);
                }
            });

            //---PJ
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                        case DialogInterface.BUTTON_POSITIVE:
                            checkMtnSub(true);
                            break;

                        case DialogInterface.BUTTON_NEGATIVE:
                            break;
                    }
                }
            };


            unSubDialog = new AlertDialog.Builder(this);
            unSubDialog.setTitle("سوتبال");
            unSubDialog.setMessage("آیا مطمئنید که میخواهید اشتراک خود را لغو کنید،\nدر این صورت دیگر نمیتوانید از امکانات اپلیکیشن استفاده نمایید.");
            unSubDialog.setNegativeButton("خیر", dialogClickListener);
            unSubDialog.setPositiveButton("بله", dialogClickListener);


            //popupMenu

            final PopupMenu popupMenu = new PopupMenu(this, img_more);
            popupMenu.getMenuInflater().inflate(com.ehin.darookhane.R.menu.menu, popupMenu.getMenu());

            img_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    popupMenu.show();
                }
            });

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    if (item.getItemId() == R.id.unsub) {


                        final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                        alertDialog.setTitle("داروخانه همـراه");
                        alertDialog.setMessage("آیا مطمئنید که میخواهید اشتراک خود را لغو کنید؟\nدر این صورت دیگر نمیتوانید از امکانات اپلیکیشن استفاده نمایید!");
                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "بله مطمئنم",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        checkMtnSub(true);
                                        if (userState) {
                                            checkMtnSub(true);
                                        } else
                                            Toast.makeText(sp, "شما اشتراک فعالی ندارید!", Toast.LENGTH_SHORT).show();

                                    }


                                });
                        alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "خیـر",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                        alertDialog.dismiss();
                                    }
                                });
                        alertDialog.show();

                    } else if (item.getItemId() == com.ehin.darookhane.R.id.support) {

                        AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
                                .setTitle("تماس با ما")
                                .setMessage("Email : jobiranian@gmail.com\nTel : 021-26471722")
                                .setPositiveButton("باشه", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                    }
                                })
                                .create();
                        alert.show();

                    }


                    return true;
                }
            });


        } else {

            //popupMenu


            final PopupMenu popupMenu = new PopupMenu(this, img_more);
            popupMenu.getMenuInflater().inflate(R.menu.menu_mci, popupMenu.getMenu());

            img_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    popupMenu.show();
                }
            });

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    if (item.getItemId() == com.ehin.darookhane.R.id.support) {

                        AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
                                .setTitle("تماس با ما")
                                .setMessage("Email : jobiranian@gmail.com\nTel : 021-26471722")
                                .setPositiveButton("باشه", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                    }
                                })
                                .create();
                        alert.show();

                    }


                    return true;
                }
            });

        }


        title_toolbar.setTypeface(font);
        txt_list.setTypeface(font);
        txt_favorite.setTypeface(font);
        txt_rate.setTypeface(font);

        database = new MyDatabase(this);
        card_list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ActivityList.class);
                startActivity(intent);
            }
        });

        card_rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                shareInCharKhoneh();
                //onClickWhatsApp();

            }
        });

        card_favorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ActivityFavorite.class);
                startActivity(intent);

            }
        });

    }

    //==================================================================================================


    public static boolean isAppInstalled(Context context, String packageName) {
        try {
            context.getPackageManager().getApplicationInfo(packageName, 0);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }

    public static String getPreferencesS(String key, Context context) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        String userName = sharedPreferences.getString(key, "0");
        return userName;
    }

    public static boolean savePreferencesS(String key, String value,
                                           Context context) {
        SharedPreferences sharedPreferences = PreferenceManager
                .getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        return editor.commit();
    }


    //---mnhpr
    public void checkMtnSub(boolean UnSub) {
        try {
            if (isReady) {
                if (UnSub) {


                    mHelper.queryInventoryAsync(mGotUnsubListener);


                } else {
                    mHelper.queryInventoryAsync(mGotInventoryListener);


                }

            }
        } catch (IabHelper.IabAsyncInProgressException e) {
        }
    }

    private String TAG = "MTNTAG";
    private IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            Log.d(TAG, "Query inventory finished.");
            if (mHelper == null) return; // Is it a failure?
            if (result.isFailure()) {
                return;
            }
            Log.d(TAG, "Query inventory was successful.");
            Log.d(TAG, "Initial inventory query finished; enabling main UI.");
            Purchase purchase = inventory.getPurchase("darookhaneh");
            if (purchase != null) {
                Log.e(TAG, purchase.getSku());
            } else {
//

                Toast.makeText(MainActivity.this, "اشتراک شما با موفقیت لغو شد.", Toast.LENGTH_SHORT).show();
                userState = false;
                savePreferencesS("userState", "false", MainActivity.this);

                Call<TokenModel> sendToken = service.laghvToken(SHPManager.getInstance().GetToken());
                sendToken.enqueue(new Callback<TokenModel>() {
                    @Override
                    public void onResponse(Call<TokenModel> call, Response<TokenModel> response) {
                        if (response.isSuccessful()) {
                            Log.e("statussssLAAAAGHV = ", response.body().getStatus().toString());
                        }
                    }

                    @Override
                    public void onFailure(Call<TokenModel> call, Throwable t) {
                        Log.e("errorrrrLAAAGHVVV = ", t.getMessage());

                    }
                });

                Intent mIntent = new Intent(MainActivity.this, SplashActivity.class);
                mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(mIntent);


                finish();

            }
        }
    };

    public void finalUnSub(String token) {
        LocalBroadcastManager.getInstance(MainActivity.this).registerReceiver(unsubAn, new IntentFilter("unsubAn"));


        AsyncHttpClient mClient;
        mClient = new AsyncHttpClient();
        mClient.get("https://seller.jhoobin.com/ws/androidpublisher/v2/applications/com.ehin.darookhane/purchases/subscriptions/darookhaneh/tokens/" + token + ":cancel?access_token=0335a83e-05d8-38cc-bb7e-cf5f64a24e5c", new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

                Intent CB = new Intent("unsubAn");
                CB.putExtra("res", responseString);
                LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(CB);


            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {

                Intent CB = new Intent("unsubAn");
                CB.putExtra("res", responseString);
                LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(CB);

            }
        });
    }

    private IabHelper.QueryInventoryFinishedListener mGotUnsubListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            Log.d(TAG, "Query inventory finished.");
            if (mHelper == null) return; // Is it a failure?
            if (result.isFailure()) {
                return;
            }
            Log.d(TAG, "Query inventory was successful.");
            Log.d(TAG, "Initial inventory query finished; enabling main UI.");
            Purchase purchase = inventory.getPurchase("darookhaneh");
            String MtnToken;
            if (purchase != null) {
                Log.e(TAG, purchase.getSku());
                MtnToken = purchase.getToken();


                if (purchase.isAutoRenewing()) {
                    finalUnSub(MtnToken);
                } else {
                    Toast.makeText(sp, "لغو عضویت برای اشتراک بدون تمدید خودکار ممکن نیست!", Toast.LENGTH_SHORT).show();
                }

            } else {
                userState = false;

                SHPManager.getInstance().SetToken(null);
                savePreferencesS("userState", "false", MainActivity.this);
                Toast.makeText(MainActivity.this, "شما اشتراک فعالی ندارید!", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MainActivity.this, SplashActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
            }
        }
    };

    private BroadcastReceiver unsubAn = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String result = intent.getExtras().getString("res");
            if (result != null) {
                Log.e(TAG, result);

                if (result.equals("{}")) {

                    Toast.makeText(context, "اشتراک شما با موفقیت لغو شد.", Toast.LENGTH_SHORT).show();
                    userState = false;
                    savePreferencesS("userState", "false", MainActivity.this);

                    Call<TokenModel> sendToken = service.laghvToken(SHPManager.getInstance().GetToken());
                    sendToken.enqueue(new Callback<TokenModel>() {
                        @Override
                        public void onResponse(Call<TokenModel> call, Response<TokenModel> response) {
                            if (response.isSuccessful()) {
                                Log.e("statussssLAAAAGHV = ", response.body().getStatus().toString());
                            }
                        }

                        @Override
                        public void onFailure(Call<TokenModel> call, Throwable t) {
                            Log.e("errorrrrLAAAGHVVV = ", t.getMessage());

                        }
                    });

                    Intent mIntent = new Intent(MainActivity.this, SplashActivity.class);
                    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(mIntent);


                    finish();

                }
            }

            LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
        }
    };

    public void onClickWhatsApp() {

        PackageManager pm = getPackageManager();
        try {

            Intent waIntent = new Intent(Intent.ACTION_SEND);
            waIntent.setType("text/plain");
            String text = "http://papricaa.com/storage/appfile/darookhanehamrah.apk";

            PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
            //Check if package exists or not. If not then code
            //in catch block will be called
            //waIntent.setPackage("com.whatsapp");

            waIntent.putExtra(Intent.EXTRA_TEXT, text);
            startActivity(Intent.createChooser(waIntent, "اشتراک گذاری از طریق ..."));

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                    .show();
        }

    }

    private void shareInCharKhoneh() {

        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(getResources().getString(R.string.charkhoneh_link)));
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace(); //no market to handle link
            Toast.makeText(getApplicationContext(), R.string.charkhoneh_error, Toast.LENGTH_LONG).show();
        }
    }


}

0 个答案:

没有答案