小编Bob*_*amu的帖子

在 Android 下载管理器上获取总字节数返回 -1

我正在创建一个进度条来显示 Android 下载管理器中下载 apk 的百分比,但DownloadManager.COLUMN_TOTAL_SIZE_BYTES总是返回-1,并且当下载完成时,它会返回文件大小。

String url = Config.GET_APK+ finalApk;
final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.addRequestHeader("Authorization", token);

// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, finalApk);
Log.d("PATH1", String.valueOf(Environment.DIRECTORY_DOWNLOADS + "/" + finalApk));
// get download service and enqueue file
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
final long downId = manager.enqueue(request);
Log.d("DOWNLOADID", String.valueOf(downId));

download.show();

new Handler().postDelayed(new Runnable() …
Run Code Online (Sandbox Code Playgroud)

android android-download-manager

5
推荐指数
1
解决办法
1283
查看次数

如何在android中以编程方式包含相同的布局两次?

我无法以编程方式调用布局,我尝试在 xml 中使用 include 及其工作

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:id="@+id/btnTes"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/LL1"
    android:orientation="vertical">

    <include layout="@layout/extend">
    </include>

    <include layout="@layout/extend">

    </include>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但我想以编程方式创建它,这是我的扩展 XML:

<TextView
    android:text="TextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView" />

<TextView
    android:text="TextView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView2" />
Run Code Online (Sandbox Code Playgroud)

这是我的java:

public class MainActivity extends AppCompatActivity {
Button btnTes;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ViewGroup tes = (ViewGroup) findViewById(R.id.LL1);
    btnTes = (Button) findViewById(R.id.btnTes);
    final View extend = LayoutInflater.from(this).inflate(R.layout.extend,null);

    btnTes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "KLIk", …
Run Code Online (Sandbox Code Playgroud)

java xml android

2
推荐指数
1
解决办法
1721
查看次数

标签 统计

android ×2

android-download-manager ×1

java ×1

xml ×1