Как скачать файл с помощью downloadManager на wear?
В самом приложение скачивание в downloadManager идёт, а вот в RemoteActivityHelper не получается выполнить этот код, может подскажете как это реализовать?
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_CODE = 100;
public static final String apkURL = "http://test.wear-store.ru/";
String apkName = "wearOs.apk";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = findViewById(R.id.image);
// storage runtime permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
}
}
image.setOnClickListener(view -> launchPlayStoreOnWear());
getContentDownload();
}
private Node getConnectedNode() {
Node returnNode = null;
Task<List<Node>> wearableList = Wearable.getNodeClient(this).getConnectedNodes();
try {
List<Node> nodes = Tasks.await(wearableList);
for (Node node : nodes) {
if (node.isNearby()) {
returnNode = node;
}
}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
return returnNode;
}
private void launchPlayStoreOnWear() {
new Thread(() -> {
Looper.prepare();
if (getConnectedNode() != null) {
RemoteActivityHelper remoteActivityHelper = new RemoteActivityHelper(this, Executors.newSingleThreadExecutor());
remoteActivityHelper.startRemoteActivity(getContentDownload());
Toast.makeText(this, "Please check your watch", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No watch is connected", Toast.LENGTH_LONG).show();
}
}).start();
}
public Intent getContentDownload() {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkURL));
request.setTitle(apkName);
request.setDescription("Downloading " + apkName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkName);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
return null;
}
}