I am developing an android application, the problem is that all activities work fine on emulator but one of the activity doesn't load on tablet (Running 4.4 kitkat) and stopes the Application, MainPage.Class is not working.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smarttrack"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme" >
<activity
android:name="com.smarttrack.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>
<activity
android:name="com.smarttrack.LoginActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.smarttrack.MainPage"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.smarttrack.AskActivity"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.smarttrack.AskLocation"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.smarttrack.Options"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.smarttrack.Settings"
android:label="#string/app_name"
android:theme="#style/ActionBarTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="com.smarttrack.MsgBroadcast">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
MainPage.Class
package com.smarttrack;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainPage extends Activity implements OnClickListener{
ImageView img;
TextView statusText;
String status ;
Button askActivity;
Button askLocation;
Button addActivity;
Button optionsMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
initVars();
img.setOnClickListener(this);
askActivity.setOnClickListener(this);
askLocation.setOnClickListener(this);
addActivity.setOnClickListener(this);
optionsMenu.setOnClickListener(this);
}
private void initVars() {
// TODO Auto-generated method stub
img = (ImageView)findViewById(R.id.switchingImage);
statusText = (TextView)findViewById(R.id.appStatus);
img.setImageResource(R.drawable.switch_off);
status = "active";
askActivity = (Button) findViewById(R.id.AskActivity);
askLocation = (Button) findViewById(R.id.btAskLocation);
addActivity = (Button) findViewById(R.id.addActivity);
optionsMenu = (Button) findViewById(R.id.optionsButton);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = v.getId();
switch(id){
case R.id.switchingImage:
Runnable swap = new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if(status == "active"){
img.setImageResource(R.drawable.switch_off);
statusText.setText("Status = Running");
status = "unactive";
}else {
img.setImageResource(R.drawable.switch_on);
statusText.setText("Status = Stopped");
status = "active";
}
}
};
img.postDelayed(swap, 100);
break;
case R.id.AskActivity:
Intent i = new Intent(this,AskActivity.class);
startActivity(i);
break;
case R.id.btAskLocation:
Intent loc = new Intent(this,AskLocation.class);
startActivity(loc);
break;
case R.id.addActivity:
break;
case R.id.optionsButton:
Intent opt = new Intent(this,Options.class);
startActivity(opt);
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar_item, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.ActionBarHelp:
AlertDialog.Builder bldr = new AlertDialog.Builder(this);
bldr.setTitle("SmartTrack").setMessage("Cool application");
Dialog dlg = bldr.create();
dlg.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
in your manifest xml your target sdk is 18 but 4.4 can run on 19
Related
So when this code runs I get no errors. It displays the buttons correctly and everything, but when I click on the button nothing happens (it just clicks and clicks and clicks nothing happens).
Below I will post the xml manifest so you can see that I have done everything perfectly, but somehow it it is not doing what I am asking it to do.
package com.Tripp.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jokecatagories);
//setting up the button references
Button jokeD = (Button) findViewById(R.id.jokeoftheday);
Button jokeC = (Button) findViewById(R.id.jokecatagories);
jokeD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),JokeOfTheDay.class);
startActivity(i);
}
});
jokeC.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent s = new Intent(".JokeCatagories");
startActivity(s);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Tripp.thebasics"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Main"
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>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".com.Tripp.thebasics.JokeCatagories"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.JOKECATAGORIES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Sweet"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SWEET" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".com.Tripp.thebasics.JokeOfTheDay"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.JOKEOFTHEDAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Change your OnClickListeners as follows...
jokeD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Menu.this, JokeOfTheDay.class);
startActivity(i);
}
});
jokeC.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent s = new Intent(Menu.this, JokeCatagories.class);
startActivity(s);
}
});
Then get rid of this <intent-filter> from the JokeCategories <activity> section in the manifest...
<intent-filter>
<action android:name="android.intent.action.JOKECATAGORIES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
...and get rid of this one from the JokeOfTheDay <activity> section...
<intent-filter>
<action android:name="android.intent.action.JOKEOFTHEDAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Basically, don't use the application Context to start an Activity (it's not necessary from an Activity as it has its own Context) and, on the whole, use explicit Intents to start Activities rather than defining <intent-filter> section in the manifest.
I created an action bar style with ANDROID ACTION BAR STYLE GENERATOR i copied the generated theme and integrated it into my app but when i run the app the action bar is blurred http://postimg.org/image/ox2saxhkt/ is a screen shot of how it looks
I've searched the web and stackoverflow but i haven't seen anyone with this kind of issue before i've done a rebuild i've tested it tdifferent emulators and it is still the same i even removed the 4.4W and 4.4L and used the 4.4.2 library to build it but no success
NOTE:I'm running on linux Kubuntu.
This is the code below
package com.pico;
import com.pico.sales.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
public class Set extends FragmentActivity implements
ActionBar.TabListener {
CollectionPagerAdapter mCollectionPagerAdapter;
ViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCollectionPagerAdapter = new CollectionPagerAdapter(
getSupportFragmentManager());
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mCollectionPagerAdapter);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mCollectionPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mCollectionPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
#Override
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
// TODO Auto-generated method stub
mViewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
// TODO Auto-generated method stub
}
public class CollectionPagerAdapter extends FragmentPagerAdapter {
final int NUM_ITEMS = 4; // number of tabs
public CollectionPagerAdapter(FragmentManager fm) {
super(fm);
}
/** This method will be invoked when a page is requested to create */
#Override
public Fragment getItem(int position) {
switch(position) {
case 0:
return new Tab1();
case 1:
return new Tab2();
case 2:
return new Tab3();
case 3:
return new Tab4();
default:
return null;
}
}
#Override
public int getCount() {
return NUM_ITEMS;
}
#Override
public CharSequence getPageTitle(int position) {
String tabLabel = null;
switch (position) {
case 0:
tabLabel = "Dashboard";
break;
case 1:
tabLabel = "Invoices";
break;
case 2:
tabLabel = "Inventory";
break;
case 3:
tabLabel = "Reports";
break;
}
return tabLabel;
}
}
}
and this is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pico.sales"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="19"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Pico" >
<activity
android:name="com.pico.MainActivity"
android:label="Please Login" >
<intent-filter>
<action android:name="android.intent.action.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.Splash"
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="com.pico.Set"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SET" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.Register"
android:label="Setup Your Account"
android:icon="#drawable/new_user" >
<intent-filter>
<action android:name="android.intent.action.REGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.Setup"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.Items"
android:parentActivityName="com.pico.Set" >
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pico.Set"
android:label="Items" >
</meta-data>
<intent-filter>
<action android:name="android.intent.action.ITEMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.No_items"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.NO_ITEMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.Pricing"
android:parentActivityName="com.pico.Set" >
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pico.Set"
android:label="Pricing Schemes" >
</meta-data>
<intent-filter>
<action android:name="android.intent.action.PRICING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.pico.No_pricing"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.NO_PRICING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:icon="#drawable/new_user"
android:name="com.pico.Customers"
android:parentActivityName="com.pico.Set" >
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pico.Set"
android:label="Customers" >
</meta-data>
<intent-filter>
<action android:name="android.intent.action.CUSTOMERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:icon="#drawable/new_user"
android:name="com.pico.No_customers" >
<intent-filter>
<action android:name="android.intent.action.NO_CUSTOMERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:icon="#drawable/new_user"
android:name="com.pico.Add_customer"
android:parentActivityName="com.pico.Customers" >
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pico.Customers"
android:label="Add_customer" >
</meta-data>
<intent-filter>
<action android:name="android.intent.action.ADD_CUSTOMER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I am trying to get the registration id of a device (testing using the emulator) to set up push notifications using GCM.
I have tried the following code, which gives me the following error:
Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION (has extras) } U=0: not found
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.pushnotifications"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission android:name="com.me.pushnotifications.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.me.pushnotifications.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="com.me.pushnotifications.MyBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.me.pushnotifications"/>
</intent-filter>
</receiver>
<activity
android:name="com.me.pushnotifications.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>
</manifest>
I am using a BroadcastReceiver to achieve the purpose:
package com.me.pushnotifications;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyBroadcastReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
Log.i("action::",action);
try{
if(action.equals("com.google.android.c2dm.intent.REGISTRATION")){
String regId = intent.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
String unregistered = intent.getStringExtra("unregistered");
Log.i("regId::",regId);
}
else if(action.equals("com.google.android.c2dm.intent.RECEIVE")){
String data = intent.getStringExtra("data");
Log.i("data::",data);
}
}
finally{
}
}
}
MainActivity
package com.me.pushnotifications;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Context context = getApplicationContext();
final String appId = getResources().getString(R.string.appId) ;
Log.i("appName::",appId);
Button activateButton,deactivateButton;
activateButton = (Button)findViewById(R.id.activateButton);
deactivateButton = (Button)findViewById(R.id.deactivateButton);
activateButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("activate::","clicked");
Intent regIntent = new Intent("com.google.android.c2dm.intent.REGISTRATION");
Log.i("intent::","created");
regIntent.putExtra("app", PendingIntent.getBroadcast(context, 0,
new Intent(), 0));
regIntent.putExtra("sender", "registration_id");
startService(regIntent);
}
});
deactivateButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("deactivate::","clicked");
Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
Log.i("intent::","created");
unregIntent.putExtra("app", PendingIntent.getBroadcast(context, 0,
new Intent(), 0));
startService(unregIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I have installed the Google API's for API Level 18. What may be the reason for the issue?
add this line in your intent-filter tag in manifest
file
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
Like this
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidhive.pushnotifications" />
</intent-filter>
Use like this:
<receiver
android:name="com.example.gcmclient.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTER" />
<category android:name="com.example.gcmclient" />
</intent-filter>
</receiver>
<service android:name="com.example.gcmclient.GcmMessageHandler" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name=".GcmIntentService" />
Is there any way to use ADT's manifest merging feature (manifestmerger.enabled=true in project.properties) in Android Studio?
1. create sample project
2. add new module
3. Module Setting
4. Remove files in App Module
Move app/~~~/values/style.xml to common/~~~/values/style.xml
edit 1.
<!-- app/~~~/AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.susemi99.manifestmergerforandroidstudio" >
<application >
<activity
android:name="kr.susemi99.common.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
edit 2.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"> <!-- add this line -->
<activity
android:name=".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>
</manifest>
edit 3.
package kr.susemi99.common;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
Toast.makeText(getApplicationContext(), "test toast", Toast.LENGTH_LONG).show();
}
return super.onOptionsItemSelected(item);
}
}
See all http://susemi99.kr/2368
I am trying to implement the in app billing and I am using http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html as my example. I have copied every file in the tutorial and only changed the name of the package. I changed my manifest so that it looks exactly like the one in the tutorial (mine has a few more things in there). As I was debugging I noticed that in my version the BillinService class was never called.
In the tutorial the Billing service's onCreate method is called after BillingHelper.setCompletedHandler is called
protected static void setCompletedHandler(Handler handler){
mCompletedHandler = handler;
}
However after it is called in my program it just continues.
Here is my review.class
package com.cellphone;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.cellphone.BillingHelper;
import com.cellphone.astralweb.R;
public class Review extends Activity implements OnClickListener {
private Context mContext;
private static final String TAG = "BillingService";
static SharedPreferences prefs;
static boolean lite;
private Button purchaseButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.reviewpage);
prefs = getSharedPreferences("Settings", 0);
lite = prefs.getBoolean("isLite", true);
String iflite = "";
if (lite) {
iflite = "-lite";
}
TextView msg1 = (TextView) findViewById(R.id.tvreview);
msg1.setText(Html
.fromHtml(cleanhtml(getText("http://www.cellphonesolutions.net/upgrade-"
+ getResources().getString(R.string.Country) + iflite))));
purchaseButton = (Button) findViewById(R.id.btntowebsite);
purchaseButton.setOnClickListener(this);
mContext = this;
startService(new Intent(mContext, BillingService.class));
BillingHelper.setCompletedHandler(mTransactionHandler);
}
public Handler mTransactionHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
Log.i(TAG, "Transaction complete");
Log.i(TAG, "Transaction status: "
+ BillingHelper.latestPurchase.purchaseState);
Log.i(TAG, "Item purchased is: "
+ BillingHelper.latestPurchase.productId);
if (BillingHelper.latestPurchase.isPurchased()) {
System.out.println("hi");
}
};
};
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btntowebsite:
if (BillingHelper.isBillingSupported()) {
BillingHelper.requestPurchase(mContext,
"android.test.purchased");
// android.test.purchased or android.test.canceled or
// android.test.refunded or com.blundell.item.passport
} else {
Log.i(TAG, "Can't purchase on this device");
purchaseButton.setEnabled(false); // XXX press button before
// service started will
// disable when it shouldnt
}
break;
default:
// nada
Log.i(TAG, "default. ID: " + v.getId());
break;
}
}
public String cleanhtml(String original) {
String finalText = original.replaceAll("<![^>]*>", "");
return finalText;
}
public String getText(String uri) {
HttpParams httpParams = new BasicHttpParams();
// 30seconds and it stops
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpConnectionParams.setSoTimeout(httpParams, 30000);
DefaultHttpClient client1 = new DefaultHttpClient(httpParams);
HttpGet request = new HttpGet(uri);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String response_str = client1.execute(request, responseHandler);
return response_str;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
#Override
protected void onDestroy() {
BillingHelper.stopService();
super.onDestroy();
}
}
Because the BillingService is never called when I first create my review class, the BillingHelper.instantiateHelper is never called
protected static void instantiateHelper(Context context, IMarketBillingService service) {
mService = service;
mContext = context;
}
so my mService and mContext come up null when I try to press my button.
Thank you for helping me out.
EDIT here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cellphone.astralweb" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application android:theme="#style/CustomTheme" android:icon="#drawable/icon_paid" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name="com.cellphone.Splash" 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>
<activity android:name="com.cellphone.LocationServiceNotification" android:screenOrientation="portrait"
android:label="#string/app_name" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.cellphone.LOCATIONSERVICENOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Registration" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.REGISTRATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.CreateAccount" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.cellphone.CREATEACCOUNT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Activate" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.ACTIVATE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.ImTracking" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.cellphone.IMTRACKING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.SpecialAdapter" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.SPECIALADAPTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.AddPerson" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.ADDPERSON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.TrackingMe" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.cellphone.TRACKINGME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.InviteFollower" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.INVITEFOLLOWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Settings" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.TabPage" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.cellphone.TABPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Review" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.REVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.help" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HELP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Maps" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.MAPS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.HelloItemizedOverlay" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HELLOITEMIZEDOVERLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.History" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HISTORY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.MyCustomLocationOverlay" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.MYCUSTOMLOCATIONOVERLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="com.cellphone.UpdateLocation" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.UPDATELOCATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service android:name=".BillingService" />
<receiver android:name=".BillingReceiver">
<intent-filter>
<action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<action android:name="com.android.vending.billing.RESPONSE_CODE" />
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
The problem was in my manifest, I named my service wrong
it should be
<service android:name="com.cellphone.BillingService" />
not <service android:name=".BillingService" />