For a research project, I'm developing an android chat application. For this, it is crucial that all users of the application should use the same, modified keyboard.
My question is the following: Is it possible to deliver a soft keyboard like the simple-keyboard (https://github.com/rkkr/simple-keyboard) with the application? Or alternatively, is it possible to force the user to utilize a certain keyboard for the text input?
Thanks in advance.
It isn't possible to force a keyboard in a non rooted phone, since there's a security block. You can however ask the user to select your keyboard as in Robert's answer:
InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();
And yes, you can add it in your application, you just need to add the keyboard code within your app, take a look a this question to see how to make a keyboard. But the most important part probably is the Manifest, because it is what will make your application show in the input method picker:
Code by Suragch:
<manifest ...>
<application ... >
<activity ... >
...
</activity>
<service
android:name=".MyInputMethodService"
android:label="Keyboard Display Name"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod"/>
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="#xml/method"/>
</service>
</application>
</manifest>
Related
So I programmed an NFC tag to launch my application that I'm currently working on. I used the following service to do that:
https://play.google.com/store/apps/details?id=com.wakdev.wdnfc&hl=en
What I want to do is to switch from one activity to another whenever the NFC tag opens my application.
Under the manifest tag in my AndroidManifest.xml I have:
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
And my MainActivity looks like this:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
Since the NFC tag opens the MainActivity first, I want to see whether it's been opened by NFC. If it has, switch to another activity.
The problem is that getIntent().getAction() always returns android.intent.action.MAIN while I'm expecting android.nfc.action.NDEF_DISCOVERED.
At the moment I'm performing this check (debugging basically) under onResume() method with the following code:
#Override
protected void onResume() {
super.onResume();
System.out.println(getIntent().getAction());
}
And I've tried performing this check under onCreate() and onStart() methods. All of them return android.intent.action.MAIN result while I expect android.nfc.action.NDEF_DISCOVERED.
I'm fresh in Android development and I'm just trying to make this work for a small prototype. Would appreciate if you guys could help me!
Edit: I got it working! I researched this question a lot and I believe that my NFC tag needed some extra data of a text/plain type (I did not specify this mimeType before as well so seems like it's mandatory). I also had put NDEF_DISCOVERED under LAUNCHER category while trying to debug the application and then changed it back to DEFAULT. I'm finally getting my desired results!
getIntent() returns the Intent that was used to create the activity. In your case, that is the home screen launcher Intent.
When you scan the NFC tag, a new Intent will be delivered to that activity. That Intent is passed to an onNewIntent() method that you can override.
Depending on how your activity is being used, you might need to handle both cases:
Where the user launched your app by scanning the NFC tag, so your activity was created with the NDEF Intent
Where the user launched your app by other means before scanning the NFC tag, so your activity was created with some other Intent and you get the NDEF Intent in onNewIntent()
I'm doing an Android project on Eclipse and I have 2 independent apps sources(Modules). How do I combine these two modules, such that when a button (present on first app) is clicked, the second app is launched?
As far I've just created the button and that's it.Any Help would be appreciated.
As I'm a beginner, please be specific :) Thank you!
In the manifest of the second app :
<activity
android:name=".MainActivitySecondApp"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.external.intentReceiver" />
</intent-filter>
</activity>
And then place the following code inside the onClickListener of the Button in the first App :
Intent intent = new Intent();
intent.setAction("com.external.intentReceiver");
context.startActivity(intent);
So, when the button is clicked, an intent of the type com.external.intentReceiver will be fired. The MainActivitySecondApp will then open since it is meant to handle such intents as defined in the Manifest.
I have an application with several activities.One of them is Login activity and this activity defined as MAIN in my app in manifest:
<activity
android:name="com.company.myapp.AuthorizationMainActivity"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The problem when my app enters background (e.g. I press home button) and then I open the app again - the Login page is showed to me. How can I show activity which was active for user at the moment application enter background?
If you don't explicitly want to use it for a special requirement, remove "android:launchMode="singleTask".
A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. (found here at Android Developes)
Use a dummy activity as your base activity that launches and in that activity check to see if you need to display the login activity or another one. Then start that specific activity you want to go to from the dummy activity.
make sure you set the dummy activity to noHistory in the manifest so the user cannot navigate back to it
if(needsLogIn){
Intent i = new Intent(this,LoginActivity.class);
startActivity(i);
}else{
Intent i = new Intent(this,OtherActivity.class);
startActivity(i);
}
Remove android:launchMode="singleTask" > singletask activity will be the root and when you press home button all the activities above it will be removed. when you remove android:launchMode="singleTask" then the default behaviour will take place ie when you press home button and then launch again it will open the activity from where you left. have a look at the link http://developer.android.com/guide/components/tasks-and-back-stack.html
I'm currently trying to implement a Search in my App. I followed Google's Tutorial but now, when i press the "Search"-Button (on the Device/Emulator), nothing appears. I'm not sure why.
My searchable.xml File:
<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/label_search"
android:hint="#string/search_hint"
android:includeInGlobalSearch="true"
>
</searchable>
This is the Android Manifest part for the Search-Activity:
<!-- Search Activity -->
<activity android:name=".SearchNotes">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
The Code which populates my ListActivity:
private void searchAndDisplay(String query){
SQLiteDatabase db = db_con.getReadableDatabase();
final Cursor c = db.rawQuery(
"SELECT headline, id as '_id' FROM entry WHERE " +
"(headline LIKE '%?%') OR (content LIKE '%?%') ",
new String[]{query, query});
this.startManagingCursor(c);
final ListAdapter searchAdapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_2, c,
new String[] {"headline", "_id"},
new int[] {android.R.id.text1, android.R.id.text2});
this.setListAdapter(searchAdapter);
db.close();
}
This doesn't work in the Emulator, neither on my Android-Device.
What am I missing here?
Do you have
<activity android:name=".OtherActivity" ... >
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchNotes" />
</activity>
inside your Activity tag? It can also be applied to the Application if you so choose.
I am afraid if android:includeInGlobalSearch="true" is causing an issue, since it requires below steps to be implemented. Try removing android:includeInGlobalSearch="true" from searchable.xml and see if it helps
To provide recent queries suggestions, you need to:
Implement a searchable activity, as described in Creating a Search Interface.
Create a content provider that extends SearchRecentSuggestionsProvider and declare it in your application manifest.
Modify the searchable configuration with information about the content provider that provides search suggestions.
Save queries to your content provider each time a search is executed.
Ref: http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html
Everything appears fine in your code. What you need to do is just after running your application you should click the Menu button in your emulator or on your mobile. This will open the search option. Choose that and you should be able to search.
In my program it adds a shortcut to the screen. I get the icon on the screen fine, but when I tap it, I get:
03-01 20:00:29.410: ERROR/AndroidRuntime(796): java.lang.SecurityException: Permission Denial: starting Intent { data=http://www.example.com/ flags=0x14000000 comp={com.isaacwaller.example/com.isaacwaller.example.ExampleCut} } from ProcessRecord{435c7398 796:android.process.acore/10005} (pid=796, uid=10005) requires null
Do you know the problem? Thanks,
Isaac
I had something like this happen when I had accidentally duplicated the activity tag for one of my activities in my manifest. I had something like this in my application section.
<activity android:name=".ConventionHome" 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="ConventionHome"></activity>
When I removed the second activity tag, things started working normally.
Figured it out, added this under <activity> tag of activity:
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
Something like this should work:
<intent-filter>
<action android:name="com.example.Project.Action"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
inside of the Activity declaration in the manifest.
I ran into this problem too, and it turned out it was because the Activity wasn't exposed to other processes. I had to add the android:exported="true" attribute to the activity tag in my manifest.
See http://developer.android.com/guide/topics/manifest/activity-element.html#exported for more information.
I haven't run into this personally but I did do some research and found the following.
Apparently whatever is attempting to invoke your app or if your app has a call to create an intent and start an activity of some intent the UID is not the same.
In ActivityManagerServer.java there are below judgement in it.
int checkComponentPermission(String permission, int pid, int uid, int reqUid)
// If the target requires a specific UID, always fail for others.
if (reqUid >= 0 && uid != reqUid) {
return PackageManager.PERMISSION_DENIED;
}
I'm going to do some testing on this and see if I can reproduce this in a test application and provide any additional feedback.
Make sure you are only trying to invoke publicly exposed activities through any intents.