Calling webservice asp.net from Android - android

I am having problems in connecting to a web service I have created.
When I try to call the webservice from my Android Code it doesn't work but when I manually write the request with variables passed in the address bar it works.
Please have a look at the code. I think the problem is with the function that I am calling on pageload, it doesn't work when I call it through Android.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Web;
using System.Data.SqlClient;
using System.Collections;
namespace MyService
{
public partial class Caller : System.Web.UI.Page
{
//public int a, b;
protected void Page_Load(object sender, EventArgs e)
{
this.txtBox1.Text = Request.QueryString["Name"];
this.txtBox2.Text = Request.QueryString["Price"];
if (txtBox1.Text != "" && txtBox2.Text != "")
Add(txtBox1.Text, Convert.ToInt32(txtBox2.Text));
}
public void Add(String name, int price)
{
//this.txtBox1.Text = Request.QueryString["Name"];
//this.txtBox2.Text = Request.QueryString["Price"];
SqlConnection con = new SqlConnection(util.ConnectionString);
con.Open();
String query = "insert into Cart values ('" + name + "',"+ price +");";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
}
}
}
Ok! When I have hosted the website on IIS and type the query in the address bar it works for example 192......../MyAndroid/Caller.aspx?Name=Banana&Price=15
This is working fine but when calling from android its not working.
Here is the android code.
try {
Connectivity c = new Connectivity();
String Name = holder.txtItemName.getText().toString();
int Price = Integer.parseInt((String)holder.txtPrice.getText());
String url="http://192.168.15.2/MyAndroid/Caller.aspx?Name="+Name+"&Price="+Price; //do not use localhost
String response=c.callWebService(url);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
A little help would be appreciated. Thank you!!
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.quiz.activities"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".QuizActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Add"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.Add" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Get"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.Get" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Related

How to read Notifications using Accessibility Services

I am trying to get incoming messages and print them. With the help of some articles, I have managed to print but with this, I am only managed to get the notification title.
I am new to android development and don't know if is it possible to get an actual message body with accessibityservice.
Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.accessibilitydemo">
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".AccessibilityActivity"
android:enabled="true"
android:exported="true"
android:label="#string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/serviceconfig" />
</service>
</application>
</manifest>
Serviceconfig.xml :
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:accessibilityFlags="flagDefault"
android:canRequestEnhancedWebAccessibility="true"
android:notificationTimeout="100"
android:packageNames="#null"
android:canRetrieveWindowContent="true"
android:canRequestTouchExplorationMode="true" />
AccessibiliActivity :
package com.domain.accessibilitydemo;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.view.accessibility.AccessibilityEvent;
public class AccessibilityActivity extends AccessibilityService {
String txtMessage;
#Override
public void onInterrupt() {
}
#Override
protected void onServiceConnected() {
System.out.println("onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
info.packageNames = null;
setServiceInfo(info);
}
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
//if(event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED){
if (event.getPackageName().toString().equals("com.whatsapp")){
StringBuilder message = new StringBuilder();
if (!event.getText().isEmpty()) {
for (CharSequence subText : event.getText()) {
message.append(subText);
}
txtMessage = message.toString();
MainActivity.textMsg.setText(txtMessage);
}
}
}
}
}
OUTPUT :
OUTPUT SCREENSHOT
How can I access the actual message?
and is there any way to store them inside a listview?
Thanks
https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord#getParcelableData()
Different types of event carry different data; For this particular kind you use getParcelableData() to get the notification body.
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
Notification notification = (Notification) accessibilityEvent.getParcelableData();
if (notification == null) return;
String title = notification.extras.getCharSequence(Notification.EXTRA_TITLE).toString();
String text = notification.extras.getCharSequence(Notification.EXTRA_TEXT).toString();
String text2 = notification.extras.getCharSequence(Notification.EXTRA_BIG_TEXT).toString();
String package_name = accessibilityEvent.getPackageName().toString();
break;

AccessibilityService issue on Android app

I am working on an Android app (academic purposes) and as part of the app I want to integrate a Keylogger. Following this answer Android Key logger I tried to implement it using AccessibilityService. The code for my class, called Keylogger.java, is the following:
import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
public class Keylogger extends AccessibilityService {
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
int tipo = event.getEventType();
switch(tipo) {
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_CLICKED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
default:
break;
}
}
#Override
public void onInterrupt() {
}
#Override
public void onServiceConnected() {
Log.d("Keylogger", "Starting service");
}
}
The Manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.mychat">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChatBoxActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".Keylogger"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
</application>
and finally, the Configuration file for the service:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames=""
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="" />
When I install the app on the device it works just fine (that is, I get no errors), and I can manually activate the service going to Settings >> Accessibility. But nothing happens next. I tried everything (launch other applications and type some text) but the prints that I placed on each case will not show up. The app does several things but from my understanding the service should work automatically. What am I missing and how can I get it right?
Thank you in advance.
https://github.com/bshu2/Android-Keylogger
Here's a android accessibility Keylogger I've used before , and works nice
I guess you can compare your application with that Keylogger , you might find your mistake

Communication between Chrome and Android Device

Hi guys I'm try to send string from Chrome app to another app following documentation but without result.
My page opened on Chrome app:
<!DOCTYPE html>
<html>
<body>
<p>URL: <a
href="intent://#Intent;scheme=printer_receiver;package=
kangel.com.printerhandler;S.name=Andrea;i.age=35;end">Do action</a></p>
</body>
</html>
My activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = findViewById(R.id.textUploaded);
//TRY ONE
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
String uri = this.getIntent().getDataString();
Log.i("PrinterHandler", "Deep link clicked " + uri);
mText.setText(uri);
}
//TRY TWO
Bundle extras = getIntent().getExtras();
if (extras != null){
String name = extras.getString("name");
Integer age = extras.getInt("age");
if (name!=null && age!=null) {
mText.setText(name);
}
}else{
mText.setText("No Data");
}
}
And manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kangel.com.printerhandler">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<data android:scheme="printer_receiver" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I click in browser, load something but never load app.
Do you have any ideas?

Android:ContentResolver.requestSync() is not triggering onPerformSync()

I am creating an Android App that is providing a button to the user to refresh the database so that the local data and the data on the server remains in sync.
I have created the Account Authenticator, Content Provider and have bind them through a service. The ContentResolver.requestSync() isnt triggering onPerformSync().
Here is what I have got for the code:
public void refreshButton(View view) {
Log.v("aye", "reached here");
Bundle settings = new Bundle();
settings.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,true);
settings.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
Account dummyAccount = createDummyAccount(this);
ContentResolver.requestSync(dummyAccount,MyContract.AUTHORITY,settings);
}
private Account createDummyAccount(Context context) {
Account dummyAccount = new Account("dummyaccount","com.example.sid.fetchdata");
AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
try {
accountManager.addAccountExplicitly(dummyAccount, null, null);
} catch (Exception e) {
e.printStackTrace();
}
ContentResolver.setSyncAutomatically(dummyAccount, MyContract.AUTHORITY, true);
ContentResolver.setIsSyncable(dummyAccount,MyContract.AUTHORITY,1);
return dummyAccount;
}
I am using a dummy account and have created a stub account authenticator according to the Android Developers Guide.
Here's how my SyncAdapter class looks like:
public class MySyncAdapter extends AbstractThreadedSyncAdapter {
private ContentResolver contentResolver;
public MySyncAdapter(Context context,boolean autoInitialize) {
super(context,autoInitialize);
contentResolver = context.getContentResolver();
}
public MySyncAdapter(Context context,boolean autoInitialize,boolean allowParallelSyncs) {
super(context,autoInitialize,allowParallelSyncs);
contentResolver = context.getContentResolver();
}
#Override
public void onPerformSync(Account account,Bundle extras,String authority,ContentProviderClient providerClient,SyncResult syncResult) {
// android.os.Debug.waitForDebugger();
// Log.e("first","Sync Started");
GetData getData = new GetData(getContext());
ContentValues[] questionsContentValues = getData.getAndParseDataContentValues();
try {
Log.d("inside","Inside");
int deletedRows = providerClient.delete(MyContract.CONTENT_URI, null, null);
// int addedRows = contentResolver.bulkInsert(MyContract.CONTENT_URI,questionsContentValues);
// providerClient.insert(MyContract.CONTENT_URI,questionsContentValues[0]);
// Log.v("third1","" + addedRows);
contentResolver.notifyChange(MyContract.CONTENT_URI,null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here's how my AndroidManfiest.xml is structured:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sid.fetchdata">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service
android:name=".RetrieveService"
android:exported="false" />
<activity
android:name=".FetchActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ListActivity"
android:label="#string/title_activity_list"
android:parentActivityName=".FetchActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.sid.fetchdata.FetchActivity" />
</activity>
<activity
android:name=".SwipeActivity"
android:label="#string/title_activity_swipe"
android:parentActivityName=".ListActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.sid.fetchdata.ListActivity" />
</activity>
<provider
android:name=".MyContentProvider"
android:syncable="true"
android:exported="true"
android:authorities="com.example.sid.fetchdata.provider" />
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/account_authenticator" />
</service>
<service
android:name=".SyncService"
android:process=":sync"
android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/my_sync_adapter" />
</service>
</application>
The corresponding classes are, MyService is bound to the MyStubAuthenticator and SyncService is bound to SyncAdapter.
The xml files for MyStubAuthenticaor:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="#mipmap/ic_launcher"
android:smallIcon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:accountType="com.example.sid.fetchdata" />
The xml file for SyncAdapter is:
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:isAlwaysSyncable="true"
android:allowParallelSyncs="false"
android:supportsUploading="false"
android:userVisible="true"
android:accountType="com.example.sid.fetchdata"
android:contentAuthority="com.example.sid.fetchdata.provider" />
The contract class for the Provider is as follows:
public class MyContract {
public static final String AUTHORITY = "com.example.sid.fetchdata.provider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + QuestionDataBaseHelper.TABLE_QUESTIONS);
public static final int QUESTIONS = 1;
public static final int QUESTIONS_ID = 2;
public static final String SINGLE_RECORD_MIME_TYPE = "vnd.android.cursor.item/vnd.com.example.sid.fetchdata.provider.questions";
public static final String MULTIPLE_RECORDS_MIME_TYPE = "vnd.android.cursor.dir/vnd.com.example.sid.fetchdata.provider.questions";
}
I have checked that the ContentProvider is working by using it on a separate thread. The account is showing up in the Accounts section in the Settings option of the phone. The Syncing is stuck at Syncing Now...
Finally fixed the problem. The problem was with the onPerformSync() function. The function was being triggered by requestSync() but
contentResolver.notifyChange(MyContract.CONTENT_URI,null);
was the problem. The function as given in the Docs tells that the last argument syncToNetwork determines if the changes are synced to the network. Since I wasn't passing it false, an infinite loop was triggered and hence the sync was taking infinite time to complete.
So the correct call would be,
contentResolver.notifyChange(MyContract.CONTENT_URI,null,false);

Translate in Android using Google API

I want to create a translate app in Android,i use Google Translate API,but it has error,please help me for fix it. This is my code
public void onClick(View v) {
// TODO Auto-generated method stub
String InputString;
String OutputString = null;
InputString = InputText.getText().toString();
try {
Translate.setHttpReferrer("http://translate.google.com.vn/");
OutputString = Translate.DEFAULT.execute(InputString, Language.ENGLISH, Language.VIETNAMESE); ////////
} catch (Exception ex) {
ex.printStackTrace();
OutputString = "Error";
}
OutputText.setText(OutputString);
}
Here is my Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stthing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Error in line Translate.setHttpReferrer("http://translate.google.com.vn/");
The method setHttpReferrer(String) is undefined for the type Translate
I am not sure if you are aware but Translate API is no longer free. so you would need to set the API key as well..
instead of using
Translate.setHttpReferrer("http://translate.google.com.vn/");
use
GoogleAPI.setHttpReferrer("http://translate.google.com.vn/");
GoogleAPI.setKey(/* Enter your API key here */);

Categories

Resources