У меня есть приложение которое коннектится к часам wear os потом на часах открывается приложение цыфеблат в playmarket. А как сделать так что бы после коннекта на часах не открывался playmarket с приложением а скачивался файл по ссылке?
Вот приложение
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = findViewById(R.id.image);
image.setOnClickListener(view -> launchPlayStoreOnWear());
}
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(
new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=" + getPackageName()))
.addCategory(Intent.CATEGORY_BROWSABLE)
);
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 class MainActivity extends AppCompatActivity {
private static final int REQUEST_CODE = 100;
public static final String apkURL = "http://test.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);
image.setOnClickListener(view -> launchPlayStoreOnWear(apkURL, apkName));
// 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);
}
}
}
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(String url, String outputFileName) {
new Thread(()->{
Looper.prepare();
if (getConnectedNode() != null) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle(apkName);
request.setDescription("Downloading " + apkName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, outputFileName);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Toast.makeText(this, "Please check your watch", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No watch is connected", Toast.LENGTH_LONG).show();
}
}).start();
}
}