I'm just trying to receive a simple SEND broadcast.
THanks
the class that wants to receive this intent has to extend BroadcastReceiver or one of its children. you then override the onReceive() method like this
Code:
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equals("MY_SEND") {
//do something
}
}
and of course on the senders end you can always do the setAction() method on the intent you are sending. setAction("MY_SEND");
Thank you, everything that I have found is some over-engineered solution.
Its always a challenge to find the piece that you need from an example/tutorial. Most of the times simpler is better
Glad i could help
From something awesome
If my Receiver class was "Receiver.java" should my androidmanifest look like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vlvgroup.TestSend"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestSend"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<receiver android:name=".receiver" android:enabled="true">
<intent-filter>
<action android:name="com.vlvgroup.TestSend.receiver" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Should work. Are you trying to recieve a broadcast from a class inside your package or from outside?
I may be wrong but the intents defined in the AndroidManifest.xml are so outside programs can send broadcasts to you. While internal private broadcasts dont need to be defined, such as one from an AlarmManager being used to do periodic work.
From something awesome
basically I want to use the "Share Page" from the browser and sent it to my app.
You mind sharing how to get an app to be in that list when you figure it out? Im not sure how its done and im interested
From something awesome
killersnowman said:
You mind sharing how to get an app to be in that list when you figure it out? Im not sure how its done and im interested
From something awesome
Click to expand...
Click to collapse
Code:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Adding that to the activity intent filters.
So how would you distinguish between the share page in the browser and share in lets say the photo app? Is it by the mimeType? Or would your app show up wherever there is a share?
From something awesome
Good question, I would I assume mimetype
Related
I'm trying to make a keyboard and I've looked at the SDK sample code, which uses InputMethodService. But if I use that, it renders a little phone-sized keyboard on the screen (I'm using an Iconia tab running honeycomb) and I want to use the whole screen's width.
Oddly, even getMaxWidth() returns 1280 or 800, so it does seem aware the display is bigger but it's not filling it.
The following simple code should reproduce what I'm seeing:
Code:
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
public class MyKeyboard extends InputMethodService {
@Override
public boolean onEvaluateFullscreenMode() {
return true;
}
}
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blah.android.softkeyboard">
<application android:label="@string/ime_name">
<service android:name=".MyKeyboard"
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>
I've just discovered if I disable compatibility mode in Spare Parts, it now works full screen. I assume I'm missing something trivial?
edit---
okay fixed. I was missing android:minSdkVersion
Dear developers,
After searching the whole internet and stackoverflow I didn't find the answer to my problem, so I need your help.
Problem
I'm trying to make an app that monitors your headset-jack-plug. To code below shows that i register the broadcast receiver and the Logcat output confirms that. But as soon as I test this app on my HTC Desire Bravo (connected to Eclipse), the onreceive method is never called.
When I replace the action.HEADSET_PLUG by action.ACTION_POWER_DISCONNECTED, the code DOES work. So when I unplug my powercable and plug it in again, my Logcat shows me the JackPlugReceiver_debug_tag.
Code
(urls replaced by #### )
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="####"
package="com.wassenaar.antitheft"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.wassenaar.antitheft.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:name="JackPlugReceiver" >
<intent-filter>
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
</receiver>
</application>
</manifest>
Code:
package com.wassenaar.antitheft;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class JackPlugReceiver extends BroadcastReceiver {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
Log.d("JackPlugReceiver_debug_tag", "onReceive method of JackPlugReceiver has run!");
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
Log.d("JackPlugReceiver_debug_tag", "Headset is unplugged");
break;
case 1:
Log.d("JackPlugReceiver_debug_tag", "Headset is plugged");
break;
default:
Log.d("JackPlugReceiver_debug_tag", "I have no idea what the headset state is");
}
}
}
}
Logcat
Code:
D/PackageManager(96): Receivers: com.wassenaar.antitheft.JackPlugReceiver
I hope you guys can help me out, I don't know what to do anymore.. Thanks!
Maybe you could share your BroadcastReceiver class and where you register it.
hgpb said:
Maybe you could share your BroadcastReceiver class and where you register it.
Click to expand...
Click to collapse
Stupid, forgot to post that! See the edit above. This is all the code I got.
From what I read, this intent is sent out FLAG_RECEIVER_REGISTERED_ONLY. You won't be able to define the intent in XML
http://stackoverflow.com/questions/6249023/detecting-whether-a-headset-is-plugged-into-an-android-device-or-not/6366238#6366238
Thanks for making this clear. Thought I already tried registering in run time, but apparently I did something wrong. Nevertheless, I learned something new. Thanks for the helpful link to stackoverflow!
Problem solved!
[Solved] I didn't see a place to mark the problem solved, so I did it here so no one would waste their time. Thanks.
I'm trying to get my app to respond anytime a new package is installed.
I have registered the intent in the manifest and created the receiver class, but I can't get onReceive to fire.
While I was playing around with it and trying to debug, I added a constructor to my receiver, and the constructor fires every time that a package is installed. The onReceive method never fires with the constructor in or out though.
I'm not sure where I am going wrong. Anyone have any ideas on what I am doing wrong? Thanks.
Code:
<receiver android:name=".InstallReceiver">
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Code:
public class InstallReceiver extends BroadcastReceiver {
public InstallReceiver()
{
//This log will display in the logcat
Log.d("InstallReceiver", "InstallReceiver constructor called.");
}
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
//This log never displays if the constructor is in or commented out
Log.d("InstallReceiver", "Install detected.");
}
}
Why do you have <category android:name="android.intent.category.DEFAULT" /> in your receiver definition? I assume your app isn't just a broadcast receiver??
It was one of the suggested fixes I found in the hours I've spent searching the internet for answers. It still has the same problem if you remove it though. I guess I just forgot to take that one out before I pasted my code.
I created a new project, and cleared all the data from my phone before uninstalling and then re-installing, and it magically started working. So, I'm not sure what the issue was.
I love the mysterious fixes!
I am trying to combine 2 android apps through a button. The first app is just a regular screen that has one button on it. The second app is an app launcher that shows all apps and opens them when clicked on. I want to make it so that when i click the button in the first app it opens up the second app. I have looked at questions similiar to mine on Stackexchange and have taken their advice by making the second app into a library and importing it, but when i click the button the app shuts down. Am i missing something?
This is the manifest file for the first app:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/symbol"
android:label="@string/app_name">
<activity
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
android:launchMode="singleTask"
android:name="com.Fuku.Eiko.MainActivity"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
android:launchMode="singleTask"
android:name="com.Assistant.Eiko.AppDrawer"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
This is my xml for button:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/symbol_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
This is the java file for the first app:
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import com.assistant.Eiko.*;
import android.content.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */ @override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(com.assistant.Eiko.R.id.button);
button.setOnClickListener
(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, com.assistant.Eiko.AppDrawer.class);
startActivity(intent);
}
});
}
I have asked this question on StackExchange but no answers yet. Thank you in advance for any help given. Please be as descriptive as possible. Also I am not using eclipse i am using AIDE( android app editor).
Sent from my GT-P3113 using XDA Premium 4 mobile app
Hi. I have a question.
I have a build a service. Before i start the service, there is an activity. In this Activity the User has 5 Buttons. My Problem now, the user should be able to select an installed app for every Button.
How i can realize it?
My Code looks like this
HTML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<PreferenceCategory
android:key="first_category"
android:title="Einstellungen">
</PreferenceCategory>
<PreferenceScreen
android:defaultValue="false"
android:key="Sub1"
android:summary="Nothing to Change"
android:title="Button 1" />
<PreferenceScreen
android:defaultValue="false"
android:key="Sub2"
android:summary="Nothing to Change"
android:title="Button 2" />
<PreferenceScreen
android:defaultValue="false"
android:key="Sub3"
android:summary="Nothing to Change"
android:title="Button 3" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub4"
android:summaryOff="WhatsApp"
android:summaryOn="Telegram"
android:title="Button 4" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub5"
android:summaryOff="Facebook"
android:summaryOn="Google Play"
android:title="Button 5" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub6"
android:summaryOff="Choose Musik Player"
android:summaryOn="Shuttle"
android:title="Button 6" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub7"
android:summaryOff="Gallery"
android:summaryOn="QuickPic"
android:title="Button 7" />
<ListPreference
android:entries="@array/listentries"
android:entryValues="@array/listvalues"
android:key="PREF_LIST"
android:summary="Untertitel"
android:title="Überschrift+Dialog" />
<!--<******.samples.Preferences.WorkingDialogPreference-->
<!--android:dialogIcon="@android:drawable/btn_dialog"-->
<!--android:dialogLayout="@layout/activity_menu_with_overlay"-->
<!--android:dialogMessage="Are you sure you wish to reset your quest progress? This action cannot be undone!"-->
<!--android:key="@string/prefKeyResetQuests"-->
<!--android:negativeButtonText="Cancel"-->
<!--android:positiveButtonText="Clear Quests"-->
<!--android:summary="Reset all quest-progress."-->
<!--android:title="Reset Quests" />-->
</PreferenceScreen>
HTML:
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
public class WorkingDialogPreference extends DialogPreference {
public WorkingDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
When i enable DialogPreference in preferences.xml my app stop. Sry for my bad English, but i hope you will understand.
Thx for Help!