Categories
discuss

Unable to start service Intent: not found

I’ve the same issue described here but i can’t understand whats wrong.

My issue is: Unable to start service Intent { act=.connections.MoodyService } U=0: not found

EDIT I’ve changed my package from connections to service in the source code, sorry for the confusion

My manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.moody"
android:installLocation="auto"
android:versionCode="0"
android:versionName="0.6.7 alpha" >

<uses-sdk
    android:maxSdkVersion="18"
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:allowClearUserData="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="activities.MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="activities.Menu_esq"
        android:label="@string/title_activity_menu_esq" >
    </activity>
    <activity
        android:name="activities.BaseActivity"
        android:label="@string/title_activity_base" >
    </activity>
    <activity
        android:name="activities.MainView"
        android:label="@string/title_activity_main_view" >
    </activity>
    <activity
        android:name="activities.LoginActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:windowSoftInputMode="adjustResize|stateVisible" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.moody.LeftActivity"
        android:label="@string/title_activity_left" >
    </activity>
    <activity
        android:name="com.example.moody.RightActivity"
        android:label="@string/title_activity_right" >
    </activity>
    <activity
        android:name="activities.UserDetailsActivity"
        android:label="@string/title_activity_user_details" >
    </activity>
    <activity
        android:name="fragments.TopicsPreview"
        android:label="@string/title_activity_copy_of_topics_preview" >
    </activity>
    <activity android:name="activities.Loading" >
    </activity>

    <service
        android:name=".service.MoodyService"
        android:icon="@drawable/ic_launcher"
        android:label="@string/moody_service" >
    </service>
</application>

service is the package and MoodyService is the class name

My service class

public class MoodyService extends Service {

public MoodyService() {
    // TODO Auto-generated constructor stub
}

private boolean isRunning = false;
Object getContent;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub

    return null;
}

@Override
public void onCreate() {
    super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    // Announcement about starting
    Toast.makeText(this, "Starting the Demo Service", Toast.LENGTH_SHORT)
            .show();

    // Start a Background thread
    isRunning = true;
    Thread backgroundThread = new Thread(new BackgroundThread());
    backgroundThread.start();

    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

@Override
public void onDestroy() {
    super.onDestroy();

    // Stop the Background thread
    isRunning = false;

    // Announcement about stopping
    Toast.makeText(this, "Stopping the Demo Service", Toast.LENGTH_SHORT)
            .show();
}

private class BackgroundThread implements Runnable {
    int counter = 0;

    public void run() {
        try {
            counter = 0;
            while (isRunning) {
                System.out.println("" + counter++);
                new Contents().getAll(getResources(),
                        getApplicationContext());
                Thread.currentThread().sleep(5000);
            }

            System.out.println("Background Thread is finished.........");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And in my main Intent.

Intent start = new Intent(".service.MoodyService");
        this.startService(start);

and also tried

Intent intent = new Intent(this, MoodyService.class);
        this.startService(intent);

and tried with the full path

<service
    android:name="com.example.moody.service.MoodyService"
    android:icon="@drawable/ic_launcher"
    android:label="@string/moody_service" >

Answer

Solved

I deleted the period in the beginning of the package name in the manifest and it worked, in another words:

This doesn’t work:

.yourPackage.YourClass

But this does work:

 yourPackage.YourClass

And in the main:

Intent intent = new Intent(this, MoodyService.class);
        this.startService(intent);

But it goes against what is written in the documentation:

android:name The name of the Service subclass that implements the service. This should be a fully qualified class name (such as, “com.example.project.RoomService”). However, as a shorthand, if the first character of the name is a period (for example, “.RoomService”), it is appended to the package name specified in the element. Once you publish your application, you should not change this name (unless you’ve set android:exported=”false”).

There is no default. The name must be specified.

Categories
discuss

Run batch file from Java code

I am trying to run a batch file that is in another directory from my Java executable. I have the following code :

    try {
        Process p =  Runtime.getRuntime().exec("cmd /c start "C:\Program Files\salesforce.com\Data Loader\cliq_process\upsert\upsert.bat"") ;           
    } catch (IOException ex) {
    }

The result is that the program opens a cmd window in the root directory where the program was run at and doesn’t access the file path I provided.

Answer

Rather than Runtime.exec(String command), you need to use the exec(String command, String[] envp, File dir) method signature:

Process p =  Runtime.getRuntime().exec("cmd /c upsert.bat", null, new File("C:\Program Files\salesforce.com\Data Loader\cliq_process\upsert"));

But personally, I’d use ProcessBuilder instead, which is a little more verbose but much easier to use and debug than Runtime.exec().

ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "upsert.bat");
File dir = new File("C:/Program Files/salesforce.com/Data Loader/cliq_process/upsert");
pb.directory(dir);
Process p = pb.start();
Categories
discuss

Radiobutton with text above button

I am new to android and I need to add radio buttons on my activity, but i need to place the text on the to of the bullet button.

Any help please. I found the following, though I dont understand what the @drawable/main_selector and @style/TabStyle.

Radiobutton with text on top

Can anyone give me a 101 guide.

UPDATE

I used the following according to some suggestion but didnt work:

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="something that is on top"
    android:id="@+id/toggle_tab_left"
    android:button="?android:attr/listChoiceIndicatorSingle"        
    style="@null"/>

<RadioButton 
    android:button="?android:attr/listChoiceIndicatorSingle"
    android:text="something that is on top"
    android:id="@+id/toggle_tab_right"
    style="@null"/>
</RadioGroup>

UPDATE 2

I got my solution from Warpzit, but befor i mark the question as answered, can someone help me on the alignment issue below. I will have 5 radio buttons in a row where some of them will have longer text split in 2 lines. when the text fit on the screen, because of landscape, or on tablets then all text should be in one line:

enter image description here

UPDATE 3

… depending on the screen size the text can split into different number of lines. It wont be always standard

enter image description here

Answer

The @style/TabStyle is simply a style that is applied, you can ignore that. The @drawable/main_selector is a graphic that is toggled depending on the situation. You can read more about selectors here.

Example to get text on top:

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:background="#f00"
    android:layout_weight="1"/>

<RadioButton 
    android:text="Text on top"
    android:button="@null"
    android:background="#0f0"
    android:layout_weight="1"/>
</RadioGroup>

Will give following result:

Behind, text on top example

If you want the Text to appear above the button you can use following xml:

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:drawableBottom="@android:drawable/btn_radio"
    android:gravity="center"
    android:layout_weight="1"/>

<RadioButton
    android:text="Text on top"
    android:button="@null"
    android:drawableBottom="@android:drawable/btn_radio"
    android:gravity="center"
    android:layout_weight="1"/>
</RadioGroup>

This will give following result:

Above example

Categories
discuss

Moment js getting next date given specified week day

I seem to have a bit of a problem getting the previous Monday given a particular date. I’m trying to use Moment js for the task. Obviously, I can do it by hand, but found it curious that I couldn’t get it to work using the example in the moment.js documentation on their website: http://momentjs.com/docs/#/get-set/day/.

I was trying something like:

moment([2013, 08, 15, 15, 20]).day(-1).format('ddd, MMM DD')

which results in the ‘two days ago’ date, that being September 13 instead of the expected September 9th.

Does anybody have a clue here? Thanks.

Answer

Here is how it works:

moment().day(1) // this monday
moment().day(-6) // last monday, think of it as this monday - 7 days = 1 - 7 = -6

Same applies in other direction:

moment().day(8) // next monday, or this monday + 7 days = 1 + 7 = 8

Your code moment().day(-1) can be explained as this Sunday – 1 day = 0 – 1 = -1 or this Saturday – 7 days = 6 – 7 = -1

Categories
discuss

Facebook ignoring part of my query string in share URL

I have a page with a Facebook Share button. The URL I want to share has a query string on it that I build with javascript. Here is how I’m generating the URL to share..

queryString = "cup=blue&bowl=red&spoon=green"; 
//the values of this are actually generated by user input, don't think its important for this example though. So in this example its just a basic string.

siteURL = "http://example.com/?share=1&";
//the url without the query string

sharingURL = siteURL+queryString; 
//Combing the domain/host with query string.. sharingURL should = http://example.com?share=1&cup=blue&bowl=red&spoon=green


function FBshare(){
  shareURL = siteURL+queryString;
  console.log(shareURL);
  window.open(
     'https://www.facebook.com/sharer/sharer.php?u='+shareURL, 
     'facebook-share-dialog', 
     'width=626,height=436'); 
  return false;
}


$(".facebook").bind("click", function(){
   FBshare();
});

When facebook grabs the URL for some reason its leaving off everything that was created in the queryString variable. So the shared URL ends up being just http://example.com/?share=1. Any ideas why its leaving off the queryString variable? The correct URL gets put into the console.log just fine, plus its in the Facebook share.php URL as a query string (for example https://www.facebook.com/sharer/sharer.php?u=http://example.com/?share=1&cup=blue&bowl=red&spoon=green).. but the actual link on Facebook is incomplete.

Here is a jsFiddle. http://jsfiddle.net/dmcgrew/gawrv/

Answer

The facebook URL comes out as this:

https://www.facebook.com/sharer/sharer.php?u=http://example.com?share=1&cup=blue&bowl=red&spoon=green

The first & and the parameter cup (as well as the other parameters) are interpreted as part of the facebook url.

Use encodeURIComponent(), which will encode special characters like &:

shareURL = encodeURIComponent(siteURL+queryString);
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..