Android应用程序:如何prevent从重新安装一个应用程序,是previously安装事后卸载用户? [英] Android App: How to prevent a user from re-installing an app that was previously installed and afterwards uninstalled?

查看:121
本文介绍了Android应用程序:如何prevent从重新安装一个应用程序,是previously安装事后卸载用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从根本上说,我想跟踪用户设备的说一些独特的设备ID,然后存储在服务器上,当用户安装我的应用程序!如果它再次尝试卸载后安装我的应用程序,然后应用程序不应该进行安装。
我怎么可能做到这一点?

Fundamentally, I want to keep track of user's device say some unique device-id which is then stored on a server when the user installs my app!and if it again tries to install my app after uninstalling, then the app should not be installed. How may I achieve this?

推荐答案

//使用下面的code找到安装了该应用或不结果
//你的应用程序包的名称是唯一的ID

//use this following code to find the app is installed or not
//your app package name is the unique id

应用程序的// appUniqueIdStr -package名称

//appUniqueIdStr -package name of the app

boolean installed  = appInstalledOrNot(appUniqueIdStr);
if(installed){
//dont install
}
else{
//install 
}


     /**
     * check app installed or not
     * @param uri is the package name of the app
     * @return boolean whether installed or not
     */
    private boolean appInstalledOrNot(String uri)
    {
        boolean app_installed = false;

        ListofAppinMyDevice getmyApp=new ListofAppinMyDevice();
        ArrayList<PInfo> apps  =getmyApp.getInstalledApps(false); /* false = no system packages */ 
        Log.e("hi", "apps==="+apps.toString());
        String uri_app=null;
        if(uri!=null)
        {
            uri_app=uri;
        }
        else 
        {
            uri_app=null;
        }

        for (int i = 0; i < apps.size(); i++)
        {

            Log.e("pack name", "apps.get(i).pname.==="+apps.get(i).pname.toString());

            if(apps.get(i).pname.toString().trim().equalsIgnoreCase(uri_app))
            {
                app_installed=true;
                Log.v("hi","im inside the loop");
                break;
            }   
        }

        Log.e("boo", "app_installed==="+app_installed);
        return app_installed ;
    }

这篇关于Android应用程序:如何prevent从重新安装一个应用程序,是previously安装事后卸载用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆