[Q] Start intent from widget - Android Software Development

I am making an app that also has a widget attached. on the widget I want to have a button that wen clicked will open the app. So I have this:
RemoteViews views = new RemoteViews("com_ice", R_layout_widget);
Intent configIntent = new Intent(context, ICE_class);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, Intent_FLAG_ACTIVITY_NEW_TASK);
views_setOnClickPendingIntent(R_id_details, configPendingIntent);
The button's ID in the widget's XML file is "details" and the app I want to open has the class ICE. The problem is that when I press the button nothing happens. Any help is appreciated.

Related

[REQ]Remapping Camera shot key to volume button?

Hi there,
First of all I tried searching on google and also in this forum itself but I cant find anything related and so i decided to create a new thread on this.
If there anyway via tweaking the registry that i can make use of the volume key on the blackstone to take pictures instead of using the touchscreen? I believe this is possible
I find taking picture using a touchscreen is really difficult.
I read from http://wiki.xda-developers.com/index.php?pagename=HTC_Blackstone_Overview that this is possible by remapping the volume rocker.
Does any know how?
Will anyone be able to help?
I'm requesting this also. HTC should have made an option for us to choose for this from the beginning.
Request also here!
Sorry, I added this "remap volume rocker Solution" because I thought it was possible, but I actually didn't try it. So let's keep this thread to find a way to do it.
Remapping keys is through AE Button Plus or MobileMagic.
Right now we only have the choice of "touch" or "touch and hold" the virtual on-screen button to "auto-focus + shot".
We need to find out if there is any keyboard shortcut associated to that function.
I tried to use the "enter key" fonction remaped to Volume Up with AE Button Plus, but it didn't work.
Does the HTC Touch Pro have HTC's Camera application? maybe they know a keyboard shortcut? Let's ask.
I guess it will be possible.... just that we need the experts here to show us how to...
[APP] CameraButton
To solve this problem. I thought of a very simple solution:
Instead of us clicking the on-screen camera button, we need an application "CameraButton", which will click on the screen for us, then we just need to map a hardware button to that application.
Simple isn't it?
So here is the C# code for the CameraButton application:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace CameraButton
{
class Program
{
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern bool SetCursorPos(int X, int Y);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
static void Main(string[] args)
{
IntPtr cameraHandle;
cameraHandle = FindWindow(null, "Camera");//search camera app
if (cameraHandle == IntPtr.Zero)// cannot find it then launch it
{
Process cam = Process.Start(new ProcessStartInfo("Camera.exe", ""));
//cameraHandle = cam.MainWindowHandle;
}
else // can find it then set position then click
{
//SetForegroundWindow(cameraHandle);// we assume we already have the focus on the camera app
SetCursorPos(240, 750 );//set position to the on-screen camera button
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
}
}
}
}
Why do I give the code rather than the binary?
Because unfortunately this code doesn't work (yet).
Let me explain a bit more:
This application doesn't need to keep running in the background, it just can do 2 things. Start the camera app if it's not already started, or just click at a specifically chosen position.
If I set the position to (0,0), my program will click at the upper-left corner of the screen, and hit the start button, therefore the start menu appears.
However if I try to click on the camera application, it doesn't have any effect!
Actually if I click somewhere else than the on-screen camera button, it should still react to the click: the little cross should move to the clicked place as part of the Touch Focus feature of HTC's camera app.
But here again, nothing happen.
Since it's my first app on WiMo, I might have done a mistake somewhere, but I can't see where.
Any XDA-developer can spot what's wrong with my code?
please see http://forum.xda-developers.com/showthread.php?t=471321
The Problem is the HTC Application, it blocks any keydown event
I did it Application released soon!
http://www.scilor.com/leocameraanykey.html

AppWidget problem when process is running

So I'm programming a application with a widget.
On my widget I got a button that starts an activity with a PendingIntent. This activity that's getting launched isn't my main activity.
Now when I'm doing it like this I get a Strange problem:
- Launching App as normal over appdrawer -> main activity opens up
- Pressing Home or Back button
- Add widget to homescreen
- Click button on widget -> nothing happens!
If I force stop my application before adding the widget to the homescreen, a click on the button on the widget opens up the activity like it should. Now I can also launch my main activity, pause it and the widget still works. So the widget only fully works if I my application isn't running in the background while adding the widget.
Has anyone of you experienced something like that?
Thank you in advance!
it is really dependent on how your onClickListener is added to the button. ive had problems where the first widget i create doesnt have the onClickListener attached but the second one will. do you mind sharing your code that you use to attach the onClickListener?
here is mine:
Code:
/** Called when the activity is first created. */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Toast.makeText(context, "onUpdate()", Toast.LENGTH_SHORT).show();
//super.onUpdate(context, appWidgetManager, appWidgetIds);
//attach an onClick intent to the layout
final Intent onClick = new Intent(context, GITextCloud.class);
onClick.setAction(LAUNCH_GMAIL_GAPPS);
PendingIntent onClickPending = PendingIntent.getBroadcast(context, 0, onClick, 0);
RemoteViews rv1 = new RemoteViews(context.getPackageName(), R.layout.gitc_html);
rv1.setOnClickPendingIntent(R.id.full_widget, onClickPending);
for (int appWidgetId : appWidgetIds) {
appWidgetManager.updateAppWidget(appWidgetId, rv1);
}
}
My code is really almost the same. Just that I need PendingIntent.getActivity instead of getBroadcast.
what flags do you set for your intent? cause if your activity is already running and thats when the button wont work it could be that you need a Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT or some other flags in the PendingIntent
try setting onClick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) or what ever your Intent is called. i think the fact that your widget and your app are going to be seperate programs means they must start in different threads. cause not all widgets need an Activity running to function
I got it now! I somehow managed to screw up my remoteviews, they didn't got updated properly.
Anyway, thanks a lot for your answers

Open Maps and show a place.

Hello, im trying to program an intent for open google maps and show a place.
I want to select the place by coordinates.
I have tested
Code:
String uri = "geo:0,0?q="+address;
context.startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
It works fine and show the location of the address with a marker
But using coordinates:
Code:
String uri = "geo:"+ lat+ "," +log;
context.startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
Is the zone is shown but there's no marker for showing the exact place.
how can I place the marker in the intent (with a label if possible)
Thanks in advance.
i take it you've seen this http://developer.android.com/guide/appendix/g-app-intents.html
it looks like it says that the use of the geo tag is underdevelopment at the moment. it might just be that the implementation of this uri is broken.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
startActivity(intent);

Problems with using multiple widgets in a single app

I have multiple widgets provided by one app, and thus multiple classes that extend AppWidgetProvider. The idea is that every widget contains a Button, which starts a Service when pressed. This Service runs a bit of code and then stops. Now for the problem: for example, I have a Widget1a and a Widget1u. These widgets look like each other, but each widget does a slightly different thing. If I place a Widget1a on the homescreen and press it, a Service is started and the code that this Service should run is run, as it should be. Now I place a Widget1u on the homescreen, and suddenly Widget1a stops working and doesn't do anything when I press it. If I place a second Widget1a on the homescreen both Widget1as work again, but now Widget1u is disabled and doesn't respond when I press it. In short: it seems that at any particular time only one type's code works when it is pressed (and if there are multiple instances of the same type on the homescreen all of these instances will work, but no instances of any other widget of my app will do anything when pressed).
The code in the AppWidgetProvider of each widget is pretty basic. It merely contains an overrided onUpdate-method. It creates an Intent to start a Service that I previously created, this is then used to create a PendingIntent which is used by setOnClickPendingIntent to make sure it can be activated by a Button in the widget. Each widget makes, when its Button is pressed, a slightly different Intent so that a certain Service is executed slightly differently. So this only works for the instances of 1 widgettype at a time, namely those of which an instance was added to the homescreen most recently.
Why do all my app's other widgets stop working when I add a widget of a different type to my homescreen? Does anyone know more about widgets or how I can make sure that each widget keeps doing its job when I add a new one from the same app to the homescreen?
Here is the onUpdate method of one of my AppWidgetProviders for one of my widgets. All widgets operate similarly and I know I used a lot of copypasting which is a bad programming habit but it didn't seem to really want to work otherwise.
Code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// Create an intent to launch the service
Intent serviceIntent = new Intent(context, SendService.class);
//I just put some extra data here to be used by the Service which wil eventually get this Intent and thus the data inside
serviceIntent.setData(Uri.parse("uri::somethingrandomandunique"));
serviceIntent.putExtra("Lamp", "1a");
// PendingIntent is required for the onClickPendingIntent that actually
// starts the service from a button click
PendingIntent pendingServiceIntent =
PendingIntent.getService(context, 0, serviceIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
// Get the layout for the App Widget and attach a click listener to the
// button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1a);
views.setOnClickPendingIntent(R.id.button1a, pendingServiceIntent);
// super.onUpdate(context, appWidgetManager, appWidgetIds);
ComponentName componentName = new ComponentName(context.getPackageName(), Widget1a.class.getName());
appWidgetManager.updateAppWidget(componentName, views);
}
So what am I doing wrong?

[NoobGuide]Click back button twice to Exit from Application

HI Guys
This is my first post in android app developement forum.
A small snippet of code which I use to exit from android app .
Many times we have more than one activites in app and often these activities are inter linked.
suppose we have four activities A-> B- ->C->D with A as root activity
Now consider user move from A to B then B--> C then come to A and moves to D
Now when user press back he returns to A
At this some app requires to be close and it should not navigate in history of activity stack ie
going to B then C then again A and finaly exit.
So the solution here is to close the app when user is in A acitivity since its Root activity.
Below is the code for that:
Code:
private static long back_pressed;
private Toast toast;
[user=439709]@override[/user]
public void onBackPressed()
{
if (back_pressed + 2000 > System.currentTimeMillis())
{
// need to cancel the toast here
toast.cancel();
// code for exit
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
// ask user to press back button one more time to close app
toast= Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT);
toast.show();
}
back_pressed = System.currentTimeMillis();
}
Add this code in your root activity so that it wont let app go into history stack.
Also you may write dialog instead of toast message
:good:
Nice snippet, thanks!
Sent from my GT-N7000 using Tapatalk 4

Categories

Resources