Read content of another app through my app - android

I have been searching the same problem for days. But unable to get any hint for that.
I need to create an app like voodoo app, which shows its custom layout only on specific pages of different apps like flipkart,etc.
Now, till this time, i have found options of using AccessebilityService and MediaProjection classes for the same. But i am stuck, how can i know programmatically, that Flipkart's Product Detail Page is visible so that i can display my app's custom view over it like Voodoo app does.
Any suggestions?

What you want to do is the following.
Using accessibility services track incoming events. Then you want to track TYPE_WINDOW_CONTENT_CHANGED events, and detect when the window content matches what you'd expect.
#Override
public void onAccessibilityEvent(AccessibilityEvent e) {
switch (e.getEventType()) {
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: {
if (isFlipkartProdcutDetailPage(getRootInActiveWindow()) {
doStuff()
}
}
}
}
public boolean isFlipkartProductDetailPage(AccessibilityNodeInfo nodeInfo) {
//Use the node info tree to identify the proper content.
//For now we'll just log it to logcat.
Log.w("TAG", toStringHierarchy(nodeInfo, 0));
}
private String toStringHierarchy(AccessibilityNodeInfo info, int depth) {
if (info == null) return "";
String result = "|";
for (int i = 0; i < depth; i++) {
result += " ";
}
result += info.toString();
for (int i = 0; i < info.getChildCount(); i++) {
result += "\n" + toStringHierarchy(info.getChild(i), depth + 1);
}
return result;
}

Related

How to add web link url in text view in Android?

I am getting few google drive attachment links. I want to show them in the text view. But they should be appeared like Attachment 1, Attachment 2 - this way.
Attachment 1 will have a web link and attachment 2 will have another. They should be clickable.
I tried this way but it is not working:
mStrAttach = new ArrayList<>();
if(attchment_arr != null)
{
for(int i = 0; i < attchment_arr.length(); i++)
{
try
{
mStrAttach.add(attchment_arr.getString(i));
}
catch (JSONException e)
{
}
}
}
if(mStrAttach.size() > 0)
{
view.attchment.setText("");
for(int k = 0; k< mStrAttach.size(); k++)
{
String devid = mStrAttach.get(k);
Log.d("Testing", "drive id::: "+devid);
SpannableString ss = new SpannableString("Attachment "+""+(k+1));
ss.setSpan(new URLSpan(devid),0,ss.length(),0);
view.attchment.append(ss + "\n");
}
Linkify.addLinks(view.attchment, Linkify.ALL);
}
But it is not coming as a link. I am not able to click the Attachment 1 or 2.
Can someone please help.
Thanks,
Arindam.
You can save your attachement link in TextView Tag,
textview1.setTag(first_link);
textview2.setTag(second_link);
then whenever you want it just use textview1.getTag(), textview2.getTag();

Android: How I can take Bracketing photos using SonyCamera remote API

This issue is troubling me until 1 week. I want to take picture like bracketing but in Sony Camera API its not support. so I coded it like continuously take 5 pictures with different value (0,+2,-2,-4,+4) using loop. (using button for it, and when press the button it should take picture 5 times) U can see the code in below:
This code for set Shutter Speed on camera
This code for taking picture:
private void takePicture() {
if (mLiveviewSurface == null || !mLiveviewSurface.isStarted()) {
DisplayHelper.toast(getApplicationContext(), R.string.msg_error_take_picture);
return;
}
new Thread() {
#Override
public void run() {
try {
JSONObject replyJson = mRemoteApi.actTakePicture();
JSONArray resultsObj = replyJson.getJSONArray("result");
JSONArray imageUrlsObj = resultsObj.getJSONArray(0);
String postImageUrl = null;
if (1 <= imageUrlsObj.length()) {
postImageUrl = imageUrlsObj.getString(0); continousShottingWithDifferentShutterValue();
}
if (postImageUrl == null) {
Log.w(TAG, "takePicture: post image URL is null.");
DisplayHelper.toast(getApplicationContext(), //
R.string.msg_error_take_picture);
return;
}
// Show progress indicator
DisplayHelper.setProgressIndicator(SonyCameraActivity.this, false);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
and this is for loop:
int val, posVal = 0;
int currentShutterSpeed = 0;
private void continousShottingWithDifferentShutterValue() {
if (val == 0) {
currentShutterSpeed = -5;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 1) {
currentShutterSpeed = 5;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 2) {
currentShutterSpeed = -10;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 3) {
currentShutterSpeed = 10;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 4) {
setShutterSpeedVal0(0);
posVal++;
}
if (posVal == 3) {
posVal = 0;
val = 0;
}
}
But when I take picture sometimes shutterSpeed or takePicture is getting error and loop is stop.
Error types are: setShutterSpeed IOExeption error: 500; or setShutterSpeed is not set. Someone works with Sonycamera remote API and has any idea how to fix it or take picture 5 times with different value. will thankful for any idea. Thanks
I solved the problem. it was a shutter speed value error. As u know in Sony Camera Api there is not have the value of shutter speed and I wrote it as in camera settings. and JSON request and response is not match so its shows error 500. If someone wants to use shutter speed value: here it is:
String shutterValue[] = {"30\"", "25\"", "20\"", "15\"", "13\"", "10\"", "8\"", "6\"",
"5\"", "4\"", "3.2\"", "2.5\"", "2\"", "1.6\"", "1.3\"", "1\"", "0.8\"", "0.6\"", "0.5\"",
"0.4\"", "1/3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30",
"1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400",
"1/500", "1/640", "1/800", "1/1000", "1/1250", "1/1600", "1/2000", "1/2500", "1/3200", "1/4000"};

Google playstore app version check not working any more

For force update I used to call the app url and check the for the html tag value <softwareVersion><softwareVersion/> but suddenly it stopped working there is no softwareVersion tag in the page so getting null. Is there any google api available to check the google play app version.
Update -
I investigate in more details when I used to call the url the response was 200 but now I am getting 405
I come up with a solution. When ever I am pushing a new version in the playstore I will add the version in the what's new, like this -
WHAT'S NEW
Version - 2.11.0
- New changes 1
- New changes 2
And I look for this Version -
So Full code looks like this -
class VersionCheckTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
String mVer = "";
String mData = "";
try {
URL mUrl = new URL(urls[0]);
BufferedReader in = new BufferedReader(new InputStreamReader(mUrl.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
if (inputLine == null)
break;
mData += inputLine;
}
in.close();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
/*
* we are looking for this tag <div itemprop="description"><content>Version - 2.11.0<br>
* We need to make sure every time we release a new version we should add the line in what's new -
*
* Version - 2.11.1
*
* - New changes 1
* - New changes 2
*/
String startToken = "Version - ";
String endToken = "<";
int index = mData.indexOf(startToken);
if (index == -1) {
mVer = null;
} else {
mVer = mData.substring(index + startToken.length(), index
+ startToken.length() + 100);
mVer = mVer.substring(0, mVer.indexOf(endToken)).trim();
}
return mVer;
}
protected void onPostExecute(String store_version) {
String currentVersion = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
currentVersion = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
Log.v(TAG, "Recv NameNotFoundException. Msg:" + e.getMessage());
}
Log.d(TAG, "store_version: " + store_version);
Log.d(TAG, "device_version: " + currentVersion);
if (store_version != null) {
if (versionCompare(store_version, currentVersion) > 0) {
dialog.setMessage(String.format(getResources().getString(R.string.update_message), getResources().getString(R.string.app_name), store_version));
dialog.show();
} else {
showDisclaimer();
}
}
}
}
public int versionCompare(String storeVersion, String currentVersion) {
String[] vals1 = storeVersion.split("\\.");
String[] vals2 = currentVersion.split("\\.");
int i = 0;
// set index to first non-equal ordinal or length of shortest version string
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
i++;
}
// compare first non-equal ordinal number
if (i < vals1.length && i < vals2.length) {
int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
return Integer.signum(diff);
}
// the strings are equal or one string is a substring of the other
// e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
return Integer.signum(vals1.length - vals2.length);
}
Maybe, at the end of march, Google changed Play store's HTML Code.
The structure of additional information has also changed.
Some developers, including me, use Jsoup to check for the latest version in the Play Store.
Perhaps you were using code like this:
Document doc = Jsoup.connect
("https://play.google.com/store/apps/details?id=name.package.your").get();
Elements Version = doc.select(".content");
for (Element v : Version) {
if (v.attr("itemprop").equals("softwareVersion")) {
VersionMarket = v.text();
}
}
but, after play store's change, your code return null.
because, "itemprop" and "sofrwareVersion" is gone, like that.
enter image description here
So, you need a new way to parse the version of your app in Google Play store's ADDITION INFORMATION with Jsoup.
try {
Document doc = Jsoup
.connect(
"https://play.google.com/store/apps/details?id=name.package.your")
.get();
Elements Version = doc.select(".htlgb ");
for (int i = 0; i < 5 ; i++) {
VersionMarket = Version.get(i).text();
if (Pattern.matches("^[0-9]{1}.[0-9]{1}.[0-9]{1}$", VersionMarket)) {
break;
}
}
The above code works as follows.
Parsing play store's your app page.
Selecting all "htlgb" contents.
like in image, "3 March 2018", "1,000+" "2.0.4", "4.4 and up, etc."
In [for Loop], [Regex] finds a value matching your version pattern (like 2.0.4) and stops.
VersionMarket is your "app version" and you can use it.
//2018-08-04 Add Comment
For some reason, the code above returns information about "Installs" instead of "version information".
Therefore, if you modify the code as shown below, you can return "version information" again.
try {
Document doc = Jsoup
.connect(
"https://play.google.com/store/apps/details?id=name.package.your")
.get();
Elements Version = doc.select(".htlgb ");
for (int i = 0; i < 10 ; i++) {
VersionMarket = Version.get(i).text();
if (Pattern.matches("^[0-9]{1}.[0-9]{1}.[0-9]{1}$", VersionMarket)) {
break;
}
}
The above code changed the number in "for break" from 5 to 10.
Because the number of "htlgb" codes has changed in Google Play Store's HTML Code.
No, no API exists for checking your app version on Play. Instead, you could implement a solution using Firebase Remote Config, then you have much more control over the minimum version your users see.

Creating TOpenDialog manually in C++ Builder XE 8 (firemonkey)

I am using C++ Builder XE8. As the TOpenDialog doesn't work on Android, I am trying to make such thing myself. My logic is very simple. It'll start to check file and folders from "/storage" and show all items on TListView. If I touch a folder (name) it'll open that folder and if I touch a file, it should show the name on a label. So I assigned a function to TListView's OnItemClick event.
Here is code. fpath is String, Label1 is showing current folder and Label2 is showing selected file.
void __fastcall TForm1::lviewitemclck(TObject * const Sender, TListViewItem * const AItem)
{
if (AItem->Text == "<< BACK") {
if (!fpath.LastDelimiter("/") == 0) {
fpath = fpath.SubString(0, fpath.LastDelimiter("/"));
Label1->Text = fpath;
Form1->showfiles(fpath);
}
}
else if ( DirectoryExists(fpath+ AItem->Text)) {
fpath = fpath+ AItem->Text;
Label1->Text = fpath;
Form1->showfiles(fpath);
}
else if (FileExists(fpath+ AItem->Text)) {
Label2->Text ="File: "+ fpath+ AItem->Text;
}
}
Below is the code of function to scan for files & folders and show them. stringlist is TStringList.
void __fastcall TForm1::showfiles (String path)
{
TSearchRec sr; // for scaning files and folders
TSearchRec fr; // to check whether the folder is accessible or not.
if (FindFirst(path+"/*", faAnyFile, sr) == 0)
{
stringlist->Clear();
stringlist->Add("<< BACK"); // being used to replace the ".."
do{
if(sr.Name != "." && sr.Name != ".."){
if (DirectoryExists(path+"/"+sr.Name)) {
if (FindFirst(path+"/"+sr.Name+"/*", faAnyFile, fr) == 0) { // to check if the folder is accessible
stringlist->Add("/"+ sr.Name);
}
FindClose(fr);
}
else{
stringlist->Add("/"+ sr.Name);
}
}
} while (FindNext(sr) == 0);
}
FindClose(sr);
stringlist->Sort();
Form1->Item->Free();
Form1->ListView1->BeginUpdate();
Form1->ListView1->ClearItems();
for( int i =0;i< stringlist->Count; i++){
Form1->Item = Form1->ListView1->Items->Add();
Form1->Item->Text = stringlist->Strings[i];
}
Form1->ListView1->EndUpdate();
}
Here the problem is, if I use ListView1->ClearItems() in TForm1::showfiles it shows me an error saying "Access violation at address (random no), accessing address 00000009". And if I dont use ClearItems() it just add more lines with already existed lines. I am a beginer, so I dont know where I am doing wrong.
You should use:
ListView1->Items->Clear
The best way I have found so far is to dynamically create TListView and delete it each time you want to add new items( or calling showfiles function). I have written a small function (named it refresh) to release already created TListView and call another function(named it create_lview ) which can create an instance again then it calls the showfiles method.
void __fastcall TForm1::refresh()
{
if (!lview1->Released()) {
try{
lview1->Release();
Form1->create_lview();
Form1->showfiles(fpath);
}
catch(...){
Label2->Text = "error in cleaning";
}
}
}
Here is the code to create the TListView whenever you want.
void __fastcall TForm1::create_lview()
{
lview1 = new TListView(Form1);
lview1->Parent = Form1;
lview1->Height = 600;
lview1->Width = 400;
lview1->Position->X = 0;
lview1->Position->Y = 0;
lview1->Visible = true;
lview1->Enabled = true;
lview1->OnItemClick = lviewitemclck;
lview1->CanSwipeDelete = false;
}
Please comment if you find any mistake or you can do it more efficiently.
I have tried another way to avoid the error by replacing the Clear method with updating the Item Text, then deletes the unused last row of the ListView within the ListView1Change event.
void __fastcall TForm1::ListView1Change(TObject *Sender)
{
//Delete last item
while (ListView1->Items->Count>stringlist->Count){
ListView1->Items->Delete(ListView1->Items->Count-1);
}
}
void __fastcall TForm1::showfiles (String path)
{
TSearchRec sr; // for scaning files and folders
TSearchRec fr; // to check whether the folder is accessible or not.
//path+PathDelim+
if (FindFirst(path+PathDelim+'*', faAnyFile, sr) == 0)
{
stringlist->Clear();
stringlist->Add("<<--BACK"); // being used to replace the ".."
do{
if(sr.Name != "." && sr.Name != ".."){
if (DirectoryExists(path+PathDelim+sr.Name)) {
if (FindFirst(path+PathDelim+sr.Name+PathDelim+"*", faAnyFile, fr) == 0) { // to check if the folder is accessible
stringlist->Add(sr.Name);
}
FindClose(fr);
}
else{
stringlist->Add(sr.Name);
}
}
} while (FindNext(sr) == 0);
}
FindClose(sr);
stringlist->Sort();
for( int i =0;i< ListView1->Items->Count; i++){
ListView1->Items->Item[i]->Text="";
}
ListView1->BeginUpdate();
try {
for( int i =0;i< stringlist->Count; i++)
{
if (ListView1->Items->Count-1<i)
{
TListViewItem* Item=ListView1->Items->Add();
Item->Text=stringlist->Strings[i];
} else
{
TListViewItem* Item=ListView1->Items->Item[i];
Item->Text=stringlist->Strings[i];
}
}
}
catch (...) {
}
ListView1->EndUpdate();
/* */
}

DTMF Tone Android [duplicate]

Is it possible to send DTMF tones in active call in android ? I tried it with proxyphone.sendDtmf() but it was useless.
How can i achieve it ?
In VOIP only it is possible,Android applications have no access to the in-call audio stream. You can fake a it a bit in speakerphone mode.
Try this method() .It is getting the number and delay from user.
private void call(int profileid) {//call procedure logic
ProfileDo profile = adapter.getProfile(profileid);
if (profile.getStepCount() == 0) {
Toast.makeText(getApplicationContext(), "Please edit the profile and add atleast one value to make a call", 10000).show();
return;}
String call = "tel:";
for (StepDO step : profile.getSteps()) {
String value = URLEncoder.encode(step.getValue());
int delay = step.getDelay();
String pausesStr = "";
for (int i = 0; i < delay / 2; i++) {
pausesStr += PhoneNumberUtils.PAUSE;
}
call += value + pausesStr;
}
startActivity(new Intent("android.intent.action.CALL", Uri.parse(call)));
}

Categories

Resources