在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:mozilla-mobile/FirefoxData-android开源软件地址:https://github.com/mozilla-mobile/FirefoxData-android开源编程语言:Java 95.5%开源软件介绍:FirefoxData for AndroidFirefoxData is an Android library that allows an application to easily access a selection of the user's Firefox Account data:
This library is also available on iOS (TODO: link). InstallationBe sure
Quick startBelow is the simplest implementation, based on SimpleExampleActivity, which is one of the examples in the examples/ module. public class MainActivity extends AppCompatActivity {
private FirefoxDataLoginManager loginManager;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // update for your implementation.
// Store a reference to the login manager,
// which is used to get a FirefoxDataClient.
loginManager = FirefoxData.getLoginManager(this);
final FirefoxDataLoginManager.LoginCallback callback = new ExampleLoginCallback();
if (!loginManager.isSignedIn()) {
loginManager.promptLogin(this, "Your app name", callback);
} else {
loginManager.loadStoredAccount(callback);
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Required callback.
loginManager.onActivityResult(requestCode, resultCode, data);
}
// Make sure this is static so we don't keep a reference
// to Context, which can cause memory leaks.
private static class ExampleLoginCallback implements FirefoxDataLoginManager.LoginCallback {
@Override
public void onSuccess(final FirefoxDataClient dataClient) {
try {
final List<HistoryRecord> history = dataClient.getAllHistory().getResult();
for (final HistoryRecord record : history) {
Log.d("FxData", record.getTitle() + ": " + record.getURI());
}
} catch (final FirefoxDataException e) {
Log.e("FxData", "failed to get data", e);
}
}
@Override
public void onFailure(final FirefoxDataException e) {
Log.e("FxData", "Failed to get DataClient", e);
}
@Override
public void onUserCancel() {
Log.d("FxData", "User cancelled log-in attempt.");
}
}
} ExplanationNotes on exposed APIs:
The private FirefoxDataLoginManager loginManager;
protected void onCreate(final Bundle savedInstanceState) {
...
loginManager = FirefoxData.getLoginManager(this); For successful logins, the following must also be called: protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
...
loginManager.onActivityResult(requestCode, resultCode, data); The public void onClick(View v) {
loginManager.promptLogin(MainActivity.this, "Your app name", callback);
} Firefox Accounts have a dashboard of all synced devices - your app name name is displayed there so the user can identify which device is which. The
Notes:
The
The Each method returns a History & passwords are largely self-explanatory but for bookmarks, we return the root bookmark folder of a tree-like structure. You can access the actual bookmarks with the following methods:
You should now have the data you need! Known issues
Questions? Feedback?We'd love to hear from you! If you have questions or feedback about using this library, you can catch us on Mozilla's IRC in the #mobile channel. If you've found a bug, we'd love it if you file an issue. Contributing to the repositorySetting up a buildAfter cloning, in Android Studio, select "File -> Open". Find your
You may also want to add a run configuration for Publishing to bintrayTo publish, ensure you have a bintray account with the appropriate permissions,
add the following to a
Increment the version number in
Coding notesThe code is laid out into a few modules:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论