gpt4 book ai didi

java - 将大量值推送到 android 中的 firebase

转载 作者:行者123 更新时间:2023-12-02 02:34:27 26 4
gpt4 key购买 nike

我想存储手机中已安装的应用程序详细信息(名称、包名称、图标)列表,我已经使用适配器在 ListView 中显示了已安装应用程序的列表。但无法将数据列表推送到 Firebase 中。任何人都可以告诉我如何从 firebase 推送和检索数据列表。

这是显示移动设备中安装的列表应用程序的代码

MainActivity.java

public class MainActivity extends AppCompatActivity {
ListView apkList;
FirebaseDatabase mFirebaseDatabase;
DatabaseReference mFireBaseReference;

ArrayList<AppLIst> arrayList;

private ArrayList<String> _listActivitiesHidden = new ArrayList();
private ArrayList<AppLIst> _listActivitiesAll = new ArrayList();
private ArrayList<AppLIst> _customApp = new ArrayList();
private String appId;

PackageManager packageManager;
AppAdapter myAdapter;

private static String userId;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFirebaseDatabase=FirebaseDatabase.getInstance();
mFireBaseReference=mFirebaseDatabase.getReference("apps");
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager
.getInstalledPackages(PackageManager.GET_PERMISSIONS);

List<PackageInfo> packageList1 = new ArrayList<PackageInfo>();

/*To filter out System apps*/
for(PackageInfo pi : packageList) {
boolean b = isSystemPackage(pi);
if(!b) {
packageList1.add(pi);
}
}
apkList = (ListView) findViewById(R.id.idListView);
myAdapter = new AppAdapter(this,packageList,packageManager);
apkList.setAdapter(myAdapter);

// apkList.setOnItemClickListener(this);
}

private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true
: false;
}

我不知道将此数据列表存储到 firebase 中。任何帮助表示赞赏。

最佳答案

来自文档:

public Task<Void> setValue (Object value)

Set the data at this location to the given value. Passing null to setValue() will delete the data at the specified location. The native types accepted by this method for the value corresponding to the JSON types:

Boolean
Long
Double
String
Map<String, Object>
List<Object>

因此,要添加,您可以执行以下操作:

mFireBaseReference = mFirebaseDatabase.getReference("apps");
mFireBaseReference.setValue(packageList1);

关于java - 将大量值推送到 android 中的 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57213209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com