SSH connection using JSCH, UnknownHostException on Android - android

I am trying to connection through SSH to my server using JSCH.
JSch jsch = new JSch();
jsch.setConfig("StrictHostKeyChecking", "no");
session = jsch.getSession(this.username, this.host, 22);
session.setPassword(this.password);
Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
this.session.connect();
The error arrives on the session.connect on the last line
12-10 00:21:35.696: W/System.err(30732): com.jcraft.jsch.JSchException: java.net.UnknownHostException: Unable to resolve host "android.widget.EditText{4257c438 VFED..CL .F....ID 219,0-849,117 #7f080008 app:id/host}": No address associated with hostname
I can successfuly reach my server with Google ConnectBot but not that way...
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:debuggable="true"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.exemple.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
</manifest>
Thanks in advance for your help !

If this.host is an Edit text then you have to call this.host.getText().toString() in jsch.getSession(). And the same for username and password, if they were Edit text objects, too.

Related

Android - Failed to access Database from another app using Content Provider

I've searching for many other answers about this failure, and no one of them solved my problem.
I have two apps, the app1 is implemented with Content Provider, and one database called students. This db is accessed normally inside app1.
But, when I fetch database from the app2, I've facing this error:
Failed to find provider info for
com.example.a436236692.myapplication.StudentsProvider
The code that are fetching students db is the same from both apps:
Uri myURI = Uri.parse("content://com.example.a436236692.myapplication.StudentsProvider/students");
ContentProviderClient myCR = getContentResolver().acquireContentProviderClient(myURI);
try {
Cursor c = myCR.query(myURI, null, null, null, "name");
if (c.moveToFirst()) {
do{
Toast.makeText(this,
c.getString(c.getColumnIndex(Constantes._ID)) +
", " + c.getString(c.getColumnIndex( Constantes.NAME)) +
", " + c.getString(c.getColumnIndex( Constantes.GRADE)),
Toast.LENGTH_SHORT).show();
} while (c.moveToNext());
}
} catch (RemoteException e) {
e.printStackTrace();
}
Debuging app 2, myCR comes with null. Them crashes application.
With my searches of this problem, I found many information that I need to grant access from package of Content Provider. Below are my manifests:
Manifest form app1:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a436236692.myapplication" >
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.READ_DATABASE"/>
<uses-permission android:name="android.permission.WRITE_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"/>
<permission android:name="com.example.a436236692.myapplication.StudentsProvider" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:permission="com.example.a436236692.myapplication.StudentsProvider">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="com.example.a436236692.myapplication.StudentsProvider"
android:authorities="com.example.a436236692.myapplication.StudentsProvider"
android:enabled="true"
android:multiprocess="true"
android:readPermission="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"
android:writePermission="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"
android:exported="true" />
</application>
</manifest>
Manifest form app2:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a436236692.testes">
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"/>
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.READ_DATABASE"/>
<uses-permission android:name="android.permission.WRITE_DATABASE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:readPermission="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"
android:writePermission="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"
android:theme="#style/AppTheme">
<activity android:name="com.example.a436236692.testes.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.a436236692.testes.ContentProviderExampleActivity" />
</application>
</manifest>
Even with permissions, inside the app1, Read and Write and other things, that I include inside the manifests, they do not affect the result.
Thanks

ACRA not sending to eMail

I am trying to send crash reports to email but when my app crashes nothing happens. I tried messing around with configurations but i just kept getting errors (unknown member mostly, wth that is). Here's my code for the class.
#ReportsCrashes(
mailTo = "me#gmail.com")
public class MyApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
My manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ghostdevelopment.ueni2"
android:versionCode="1"
android:versionName="1.0"
android:debuggable="true">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="25" />
<application
android:name="MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:label="#string/app_name"
android:name="com.ghostdevelopment.ueni2.MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Ship Database"
android:name=".ShipInfo" />
</application>
</manifest>
According to your logcat it appears that your app has not included the ACRA library. You need to configure your build so that ACRA is included in your APK.

RECEIVE_BOOT_COMPLETED does not work

I am trying to write in file after android device boots. I have checked everything related to this topic here but none of them worked for me. My phone is Huawei Honor (H30-U10) and it's rooted. Android version 4.2.2. Here is my code:
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bog.ddrc.technicianmobile"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name="bog.ddrc.technicianmobile.App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="bog.ddrc.technicianmobile.activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:enabled="true"
android:name="bog.ddrc.technicianmobile.StartTMServiceAtBootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
StartTMServiceAtBootReceiver.java:
public class StartTMServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String data = "text";
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "test.txt");
try {
OutputStream os = new FileOutputStream(file);
os.write(data.getBytes());
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Remove
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
from your <receiver> block.
After trying all of mentioned answers and tricks, I finally find why the code is not work in my phone. Some Android phones like "Huawei Honor 3C Android 4.2.2" have a Statup Manager menu in their settings and your app must be checked in the list. :)

CreateNdefMessageCallback conflict with ContentProvider permissions

I write a program provider a provider for another apps of our company. The provider need a permission to access the data.
We also have a interface need use NFC send json data to another devices.
When we access the provider in CreateNdefMessageCallback.createNdefMessage like
#Override
public NdefMessage createNdefMessage(NfcEvent event) {
Context context = this;
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(Uri.parse("content://demo/data-lists"),
null,
null,
null,
null);
// FIXME Strange: Will never goes here ...
mMessage = getMessage(cursor);
NdefMessage msg = new NdefMessage(
new NdefRecord[] {
createMimeRecord(mMimeType, mMessage.getBytes())
});
return msg;
}
There is very strange, we never get a cursor until remove the permission.
Permission Declear
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
Request permision
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
Provider permission declear
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
Currenty the provider and the NFC-send activity in the same application and read the provider data will but the NFC callback.
And if I remove the permission for the provider, this will work fine.
like the
Provider without permission
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"/>
Please help.
Thanks.
UPDATED 2013-03-14
It's very strange. I found this issue only when the provider and the NFC Activity in the same application. like this.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
<activity
android:name=".ui.MainTabActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
</manifest>
But if I use two separated application, it works will like.
<!-- Application Provider -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo.provider"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
</manifest>
<!-- Application UI -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo.ui"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
<activity
android:name=".ui.MainTabActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>

InMobi ad do not display on activity

Below is my code snippet... There is no error, but the ad is not showing on the activity... I do not know what I am missing.. PLease HELP!
public class InMobiAdActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
IMAdView imAdView = new IMAdView(this, IMAdView.INMOBI_AD_UNIT_320X50,"4028cba631d63df10131e1d3818b00cc (code taken from inmobi wiki as sample code for testing ads");
LinearLayout layout = (LinearLayout)findViewById(R.id.ll);
layout.addView(imAdView);
IMAdRequest adRequest = new IMAdRequest();
adRequest.setTestMode(true);
imAdView.setIMAdRequest(adRequest);;
imAdView.loadNewAd();
}
}
On my Logcat it shows;
10-08 14:23:02.534: D/InMobiAndroidSDK_3.6.0(2388): requestactivity=AdRequest&u-rt=0&d-device-screen-density=1.5&d-device-screen-size=480X800&mk-siteid=4028cba631d63df10131e1d3818b00cc&u-id-map=fGtq8K%2F5btMGW7t0WElg0rMcqUSCfbWD8E%2FCvECMDB9eWL5VBtsR3k9awVDmgjD4BS024QxddQlU%0AmAdObyz5KA%3D%3D%0A&u-id-key=-1447871561&u-key-ver=1&aid=b281bb6c-ddd8-4ffe-bb5d-395be16b6607&mk-version=pr-SAND-DTGTA-20120915&mk-rel-version=pr-SAND-DTGTA-20120915&format=xhtml&mk-ads=1&h-user-agent=Mozilla%2F5.0+%28Linux%3B+U%3B+Android+2.3.3%3B+en-us%3B+sdk+Build%2FGRI34%29+AppleWebKit%2F533.1+%28KHTML%2C+like+Gecko%29+Version%2F4.0+Mobile+Safari%2F533.1&u-appBId=com.dtan.inmobi&u-appDNM=InMobiAndroidSDKSampleApp&u-appVer=1.0&d-localization=en_us&d-netType=umts&d-orientation=1&mk-ad-slot=15
10-08 14:23:02.684: I/ActivityManager(61): Displayed com.dtan.inmobi/.InMobiAdActivity: +1s472ms
EDIT:
Here is my Manifest. All the permissions are indicated here as well;
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dtan.inmobi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".InMobiAdActivity"
android:label="title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.inmobi.androidsdk.IMBrowserActivity" android:configChanges="keyboardHidden|orientation|keyboard" />
</application>
</manifest>
Try below Post For Fixing Connect Internet To Emulator
Android Emulator is not connecting to internet
android emulator browser not connecting to internet
Find More Help From Google Here
if u find same problem try to check it real device with internet connectivity!

Categories

Resources