我正在使用android facebook sdk。我有问题当divice安装了facebook应用程序(无效密钥哈希)我在此代码中收到了keyhash
public class SpleshScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splesh_screen);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"mypackage",
PackageManager.GET_SIGNATURES);
for (android.content.pm.Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.wtf("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 2 seconds
sleep(2 * 1000);
//
// Log.e("asdasdasdasd",my_json );
// After 2 seconds redirect to another intent
Intent in = new Intent(getApplicationContext(),
MainmoviesActivity.class);
startActivity(in);
// Remove activity
finish();
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
}
我在我的脸书应用程序中添加了这个keyhash。 我有问题只有当divice有facebook应用程序时(当我用USB运行我的应用程序时) 我究竟做错了什么?如果有人知道解决方案,请帮助我
答案 0 :(得分:0)
因为生成的哈希键是错误的。
要解决此问题,请执行以下步骤:
将以下代码粘贴到oncreate()。
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.example.packagename",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
见这个帖子
https://stackoverflow.com/a/23863110/2176734
这肯定会解决你的问题。
答案 1 :(得分:0)