阅读从申请preferences而不是从AndroidManifest.xml中的信息 [英] Read informations from application preferences instead from AndroidManifest.xml

查看:345
本文介绍了阅读从申请preferences而不是从AndroidManifest.xml中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android开发新的,我使用的Eclipse开发Android应用程序。我提供了一个功能,同步于Dropbox的数据库。要做到这一点,Dropbox的给我用于身份验证的密钥值。此键已经在AndroidManifest.xml中插入

I'm new in Android dev and I'm developing an Android App using Eclipse. I provided a functionality to Synchronize database on Dropbox. To do it, Dropbox give me a key value to use for authentication. This key have to be inserted in AndroidManifest.xml

<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask" >
<intent-filter>
    <!-- Change this to be db- followed by your app key -->
    <data android:scheme="db-xxxxxxxxxx" />

    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

但是,使用这种逻辑,最终用户将无法更改此值数据库上他的Dropbox帐户同步,而不是我的。我做了一个preference画面存储在应用preferences的关键,但我不觉得code,其中值从Android清单读取。我认为这是这里,但我新我不明白如何编辑我的code:

But using this logic, the end user will not be able to change this value to synchronize database on his dropbox account, and not on my. I've made a preference screen to store the key in Application Preferences, but I' don't find code where the value is read from Android Manifest. I think it's about here but I'm new and I don't understand how to edit my code:

 public void startAuthentication(Context context) {
    AppKeyPair appKeyPair = getAppKeyPair();

    // Check if the app has set up its manifest properly.
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    String scheme = "db-" + appKeyPair.key;
    String uri = scheme + "://" + AuthActivity.AUTH_VERSION + "/test";
    testIntent.setData(Uri.parse(uri));
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(testIntent, 0);

    if (0 == activities.size()) {
        throw new IllegalStateException("URI scheme in your app's " +
                "manifest is not set up correctly. You should have a " +
                "com.dropbox.client2.android.AuthActivity with the " +
                "scheme: " + scheme);
    } else if (activities.size() > 1) {
        // Check to make sure there's no other app with this scheme.
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("Security alert");
        builder.setMessage("Another app on your phone may be trying to " +
                "pose as the app you are currently using. The malicious " +
                "app cannot access your account, but linking to Dropbox " +
                "has been disabled as a precaution. Please contact " +
                "support@dropbox.com.");
        builder.setPositiveButton("OK", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
        return;
    } else {
        // Just one activity registered for the URI scheme. Now make sure
        // it's within the same package so when we return from web auth
        // we're going back to this app and not some other app.
        String authPackage = activities.get(0).activityInfo.packageName;
        if (!context.getPackageName().equals(authPackage)) {
            throw new IllegalStateException("There must be an " +
                    "AuthActivity within your app's package registered " +
                    "for your URI scheme (" + scheme + "). However, it " +
                    "appears that an activity in a different package is " +
                    "registered for that scheme instead. If you have " +
                    "multiple apps that all want to use the same access" +
                    "token pair, designate one of them to do " +
                    "authentication and have the other apps launch it " +
                    "and then retrieve the token pair from it.");
        }
    }

    // Start Dropbox auth activity.
    Intent intent = new Intent(context, AuthActivity.class);
    intent.putExtra(AuthActivity.EXTRA_INTERNAL_CONSUMER_KEY,
            appKeyPair.key);
    intent.putExtra(AuthActivity.EXTRA_INTERNAL_CONSUMER_SECRET,
            appKeyPair.secret);
    if (!(context instanceof Activity)) {
        // If starting the intent outside of an Activity, must include
        // this. See startActivity(). Otherwise, we prefer to stay in
        // the same task.
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    context.startActivity(intent);

你能帮助我吗?

感谢您提前

推荐答案

我觉得你可能误解是什么键的用途。它不是用来选择哪一个帐户与同步文件。

I think that you may be misunderstanding what that key is used for. It is not used for choosing which account to sync files with.

你想改变的关键是一个应用程序API密钥。除非你是谁也有自己的API密钥已经开发定位的每个用户并不需要一个独特的密钥。这是用来识别您的应用程序,并关闭它,除其他事项外,它是否造成麻烦的Dropbox。

The key you want to change is an APP API key. Each user does not need a unique key unless you are targeting at developers who would have their own API keys already. This is used to identify your app and shut it down, among other things, if it's causing trouble for Dropbox.

这关键你想编辑的具体实例是有控制返回到您的应用程序用户与他们的个人账户进行身份验证后。这需要保持同步你叫AppKeyPair appKeys =新AppKeyPair(APP_KEY,APP_SECRET)时用于身份验证的关键;

The specific instance of this key you are trying to edit is what gets control back to your app after a user authenticates with their personal account. This needs to be kept in sync with the key you use for authentication when calling AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);

您将无法在运行时修改数据标签实现这一意图过滤器。

You will not be able to modify the the data tag in that intent filter at runtime.

这篇关于阅读从申请preferences而不是从AndroidManifest.xml中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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