我正在创建一个进度条来显示 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) 我无法以编程方式调用布局,我尝试在 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)