我是Android開發人員中的新成員,並且正在使用Eclipse開發Android應用程序。我提供了一個在Dropbox上同步數據庫的功能。要做到這一點,Dropbox爲我提供了一個用於身份驗證的關鍵值。此鍵已經在AndroidManifest.xml中從應用程序首選項中讀取信息,而不是從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帳戶同步,而不是我的。我製作了一個首選項屏幕,將密鑰存儲在應用程序首選項中,但是我沒有找到從Android Manifest中讀取值的代碼。我認爲這是關於這裏,但我是新的,我不知道如何編輯我的代碼:
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 " +
"[email protected]");
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);
你能幫我嗎?
謝謝您提前
謝謝你的建議......但我很困惑:( 最終用戶將能夠上傳數據庫在他的收件箱空間?使用哪些鍵? – Daniele
您的鑰匙。鑰匙是爲應用程序,他們沒有什麼如果你只是想讓我能夠從你的應用程序上傳數據庫到我自己的個人帳戶,那麼你把你的應用程序API密鑰,每個人都使用相同的。將要求每個用戶登錄到他們的個人帳戶 –
aaaaahhh ...好吧給我的鑰匙「識別」我的應用程序,而不是我的帳戶!所以,當最終用戶嘗試同步數據庫時,sdk詢問他的帳戶憑證和數據庫將被上傳到他的帳戶。這是正確的? – Daniele