3

我有一个要求,如果我在一个 Android 设备上运行我的应用程序,然后尝试在另一个 Android 设备上运行相同的应用程序,我需要先检查它是否是另一台设备,如果是,那么我应该继续。您能否告诉我是否有任何方法可以实现这一目标?

谢谢你。

4

3 回答 3

2

你可以使用这个:

telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
telephonyManager.getSimSerialNumber();

getDeviceId并且getSimSerialNumber每个设备都是唯一的,因此您可以检查此值

于 2013-02-06T08:56:49.793 回答
0

要实现这一点,问题是这样的:

How can we differentiate, if we are installing app,
first time on 1st device or first time on second device.
so for that we have to use a unique key for app to run 
on each different device.
So that before saving shared pref,
we can validate the unique key for that device. 

现在的问题是用户将如何获得唯一密钥?因此,假设应用程序供应商将为每个设备提供密钥。但为此,应用程序应该有一些算法来验证我们提供的密钥。

但不幸的是,如果供应商提供密钥,用户也可以使用该密钥安装在另一台设备上。

所以最终解决方案是在首次运行应用程序之前必须在某些 Web 服务上注册设备以进行激活。

于 2013-02-06T14:50:50.407 回答
-1

在第一次运行时在共享首选项中设置一个标志

SharedPreferences preferences = getSharedPreferences("PREF_NAME", 0);
boolean onlyonce = preferences.getBoolean("FLAG_NAME", false);

if (!onlyonce ) {
   SharedPreferences.Editor editor = preferences.edit();
   editor.putBoolean("FLAG_NAME", true);
   editor.commit();
}

如果用户重置应用程序,它也会被清除,这是有风险的。这会解决你的问题吗?

于 2013-02-06T08:57:36.863 回答