Search Results

Search found 1372 results on 55 pages for 'intent'.

Page 12/55 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Android Notification with AlarmManager, Broadcast and Service

    - by user2435829
    this is my code for menage a single notification: myActivity.java public class myActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mylayout); cal = Calendar.getInstance(); // it is set to 10.30 cal.set(Calendar.HOUR, 10); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); long start = cal.getTimeInMillis(); if(cal.before(Calendar.getInstance())) { start += AlarmManager.INTERVAL_FIFTEEN_MINUTES; } Intent mainIntent = new Intent(this, myReceiver.class); pIntent = PendingIntent.getBroadcast(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager myAlarm = (AlarmManager)getSystemService(ALARM_SERVICE); myAlarm.setRepeating(AlarmManager.RTC_WAKEUP, start, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pIntent); } } myReceiver.java public class myReceiver extends BroadcastReceiver { @Override public void onReceive(Context c, Intent i) { Intent myService1 = new Intent(c, myAlarmService.class); c.startService(myService1); } } myAlarmService.java public class myAlarmService extends Service { @Override public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); } @SuppressWarnings("deprecation") @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); displayNotification(); } @Override public void onDestroy() { super.onDestroy(); } public void displayNotification() { Intent mainIntent = new Intent(this, myActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentIntent(pIntent) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_noti) .setTicker(getString(R.string.notifmsg)) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notifmsg)); nm.notify(0, builder.build()); } } AndroidManifest.xml <uses-permission android:name="android.permission.WAKE_LOCK" /> ... ... ... <service android:name=".myAlarmService" android:enabled="true" /> <receiver android:name=".myReceiver"/> IF the time has NOT past yet everything works perfectly. The notification appears when it must appear. BUT if the time HAS past (let's assume it is 10.31 AM) the notification fires every time... when I close and re-open the app, when I click on the notification... it has a really strange behavior. I can't figure out what's wrong in it. Can you help me please (and explain why, if you find a solution), thanks in advance :)

    Read the article

  • Android Actionbar Tabs + Fragments + Service

    - by Vladimir
    So, I have 3 problems with my code: 1) I want that each tab saves its state. So that a TextView shows changed text if it was changed. 2) if I go to Tab2 then to Tab1 I can't see the content of the fragments. Only if I touch on the already selected tab, it shows me the content 3) I can't correctly connect/bind and unbind service to Fragment Text must be changed from Service. Please help, I don't know how I realize my intent. MyActivity.java package com.example.tabs; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.RunningServiceInfo; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; public class MyActivity extends Activity { private static String ACTION_BAR_INDEX = "ACTION_BAR_INDEX"; private Tab tTab1; private Tab tTab2; private static MyService.MyBinder myBinder; private static Intent myServiceIntent; private static MyService myService; private TabListener<Tab1> tab1Listener; private TabListener<Tab2> tab2Listener; private static ServiceConnection myConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder binder) { myBinder = (MyService.MyBinder) binder; myService = myBinder.getService(); myBinder.setCallbackHandler(myServiceHandler); } public void onServiceDisconnected(ComponentName name) { myService = null; myBinder = null; } }; /** Callbackhandler. */ private static Handler myServiceHandler = new Handler() { public void handleMessage(Message message) { super.handleMessage(message); Bundle bundle = message.getData(); if (bundle != null) { String text = bundle.getString("Text1", ""); if (!text.equals("")) { } } } }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myServiceIntent = new Intent(this, MyService.class); bindService(myServiceIntent, myConnection, Context.BIND_AUTO_CREATE); if (!isServiceRunning()) { startService(myServiceIntent); } final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(false); tTab1 = actionBar.newTab(); tab1Listener = new TabListener<Tab1>(this, R.id.fl_main, Tab1.class); tTab1.setTag("Tab_1"); tTab1.setText("Tab_1"); tTab1.setTabListener(tab1Listener); tTab2 = actionBar.newTab(); tab2Listener = new TabListener<Tab2>(this, R.id.fl_main, Tab2.class); tTab2.setTag("Tab_2"); tTab2.setText("Tab_2"); tTab2.setTabListener(tab2Listener); actionBar.addTab(tTab1, 0); actionBar.addTab(tTab2, 1); } @Override public void onResume() { super.onResume(); SharedPreferences sp = getPreferences(Activity.MODE_PRIVATE); int actionBarIndex = sp.getInt(ACTION_BAR_INDEX, 0); getActionBar().setSelectedNavigationItem(actionBarIndex); } protected void onSaveInstanceState(Bundle outState) { // Save the current Action Bar tab selection int actionBarIndex = getActionBar().getSelectedTab().getPosition(); SharedPreferences.Editor editor = getPreferences(Activity.MODE_PRIVATE).edit(); editor.putInt(ACTION_BAR_INDEX, actionBarIndex); editor.apply(); // Detach each of the Fragments FragmentTransaction ft = getFragmentManager().beginTransaction(); if (tab2Listener.fragment != null) { ft.detach(tab2Listener.fragment); } if (tab1Listener.fragment != null) { ft.detach(tab1Listener.fragment); } ft.commit(); super.onSaveInstanceState(outState); } protected void onRestoreInstanceState(Bundle savedInstanceState) { // Find the recreated Fragments and assign them to their associated Tab // Listeners. tab1Listener.fragment = getFragmentManager().findFragmentByTag(Tab1.class.getName()); tab2Listener.fragment = getFragmentManager().findFragmentByTag(Tab2.class.getName()); // Restore the previous Action Bar tab selection. SharedPreferences sp = getPreferences(Activity.MODE_PRIVATE); int actionBarIndex = sp.getInt(ACTION_BAR_INDEX, 0); getActionBar().setSelectedNavigationItem(actionBarIndex); super.onRestoreInstanceState(savedInstanceState); } public boolean isServiceRunning() { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (MyService.class.getName().equals(service.service.getClassName())) { return true; } } return false; } @Override protected void onDestroy() { super.onDestroy(); unbindService(myConnection); stopService(myServiceIntent); } public static class TabListener<T extends Fragment> implements ActionBar.TabListener { private Fragment fragment; private Activity activity; private Class<T> fragmentClass; private int fragmentContainer; public TabListener(Activity activity, int fragmentContainer, Class<T> fragmentClass) { this.activity = activity; this.fragmentContainer = fragmentContainer; this.fragmentClass = fragmentClass; } public void onTabReselected(Tab tab, FragmentTransaction ft) { if (fragment != null) { ft.attach(fragment); } } public void onTabSelected(Tab tab, FragmentTransaction ft) { if (fragment == null) { String fragmentName = fragmentClass.getName(); fragment = Fragment.instantiate(activity, fragmentName); ft.add(fragmentContainer, fragment, fragmentName); } else { ft.detach(fragment); } } public void onTabUnselected(Tab tab, FragmentTransaction ft) { if (fragment != null) { ft.detach(fragment); } } } } MyService.java package com.example.tabs; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; public class MyService extends Service { private final IBinder myBinder = new MyBinder(); private static Handler myServiceHandler; public IBinder onBind(Intent intent) { return myBinder; } public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); return START_STICKY; } public void sendMessage(String sText, int id) { Bundle bundle = new Bundle(); bundle.putString("Text" + id, sText); Message bundleMessage = new Message(); bundleMessage.setData(bundle); myServiceHandler.sendMessage(bundleMessage); } public class MyBinder extends Binder { public MyService getService() { return MyService.this; } public void setCallbackHandler(Handler myActivityHandler) { myServiceHandler = myActivityHandler; } public void removeCallbackHandler() { myServiceHandler = null; } } } Tab1.java package com.example.tabs; import android.app.Activity; import android.app.Fragment; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Tab1 extends Fragment { public static String TAG = Tab1.class.getClass().getSimpleName(); private static TextView tvText; private EditText editText; private static MyService.MyBinder myBinder; private static Intent myServiceIntent; private static MyService myService; private static ServiceConnection myConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder binder) { myBinder = (MyService.MyBinder) binder; myService = myBinder.getService(); myBinder.setCallbackHandler(myServiceHandler); } public void onServiceDisconnected(ComponentName name) { myService = null; myBinder = null; } }; /** Callbackhandler. */ private static Handler myServiceHandler = new Handler() { public void handleMessage(Message message) { super.handleMessage(message); Bundle bundle = message.getData(); if (bundle != null) { String text = bundle.getString("Text1", ""); if (!text.equals("")) { tvText.setText(text); } } } }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tab1, container, false); tvText = (TextView) view.findViewById(R.id.tv_tab1); editText = (EditText) view.findViewById(R.id.editText1); Button btn1 = (Button) view.findViewById(R.id.btn_change_text_1); btn1.setOnClickListener(new OnClickListener() { public void onClick(View v) { myService.sendMessage(String.valueOf(editText.getText()), 1); } }); return view; } @Override public void onAttach(Activity activity) { super.onAttach(activity); myServiceIntent = new Intent(activity, MyService.class); activity.bindService(myServiceIntent, myConnection, Context.BIND_AUTO_CREATE); } @Override public void onDetach() { super.onDetach(); getActivity().unbindService(myConnection); } } Tab2.java package com.example.tabs; import android.app.Activity; import android.app.Fragment; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Tab2 extends Fragment { public static String TAG = Tab2.class.getClass().getSimpleName(); private static TextView tvText; private EditText editText; private static MyService.MyBinder myBinder; private static Intent myServiceIntent; private static MyService myService; private static ServiceConnection myConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder binder) { myBinder = (MyService.MyBinder) binder; myService = myBinder.getService(); myBinder.setCallbackHandler(myServiceHandler); } public void onServiceDisconnected(ComponentName name) { myService = null; myBinder = null; } }; /** Callbackhandler. */ private static Handler myServiceHandler = new Handler() { public void handleMessage(Message message) { super.handleMessage(message); Bundle bundle = message.getData(); if (bundle != null) { String text = bundle.getString("Text1", ""); if (!text.equals("")) { tvText.setText(text); } } } }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tab2, container, false); tvText = (TextView) view.findViewById(R.id.tv_tab2); editText = (EditText) view.findViewById(R.id.editText2); Button btn2 = (Button) view.findViewById(R.id.btn_change_text_2); btn2.setOnClickListener(new OnClickListener() { public void onClick(View v) { myService.sendMessage(String.valueOf(editText.getText()), 2); } }); return view; } @Override public void onAttach(Activity activity) { super.onAttach(activity); myServiceIntent = new Intent(activity, MyService.class); activity.bindService(myServiceIntent, myConnection, Context.BIND_AUTO_CREATE); } @Override public void onDetach() { super.onDetach(); getActivity().unbindService(myConnection); } } main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:orientation="vertical" > </LinearLayout> tab1.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:ems="10" android:inputType="text" > <requestFocus /> </EditText> <Button android:id="@+id/btn_change_text_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:text="Change text" /> <TextView android:id="@+id/tv_tab1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TAB1\nTAB1\nTAB1" /> </LinearLayout> tab2.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" > <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:ems="10" android:inputType="text" > <requestFocus /> </EditText> <Button android:id="@+id/btn_change_text_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:text="Change text" /> <TextView android:id="@+id/tv_tab2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:text="TAB2\nTAB2\nTAB2" /> </LinearLayout> AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.tabs" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="TabsPlusService" android:theme="@android:style/Theme.Holo" > <activity android:name="com.example.tabs.MyActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="TabsPlusService" android:theme="@android:style/Theme.Holo" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".MyService" android:enabled="true" > </service> </application> </manifest>

    Read the article

  • Android local search

    - by Aleksander O
    Hi! I'm trying to implement a local search in my activity. I've added an appropriate intent filter and metadata tag to manifest file but if I click Search button it invokes standard android search box. What's my problem? Manifest file: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nixsolutions.invertigation.android.dataprovider" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <provider android:name="NoteProvider" android:authorities="com.nixsolutions.investigation.android.NoteProvider"> </provider> <activity android:name="NotesList"> <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.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application> <uses-sdk android:minSdkVersion="7" /> </manifest> searchable.xml: <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="Custom search" android:hint="Custom hint" android:searchMode="showSearchLabelAsBadge" />

    Read the article

  • zxing project on android

    - by Aisthesis Cronos
    Hello everybody Many weeks ago,I tried to work on a mini project on Android OS requires ZXING, I followed several tutorials on this web site and on other Example: tuto1, and many tags and tutorials here tuto2, tuto3 ... But I failed each time. I can't import the android project into eclipse IDE to compile it with my code "not via Intent zxing APK-and my program like this example : private Button.OnClickListener btScanListener = new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); try { startActivityForResult(intent, REQUEST_SCAN); } catch (ActivityNotFoundException e) { Toast.makeText(Main.this, "Barcode Scanner not intaled ", 2000).show(); } } }; public void onActivityResult(int reqCode, int resCode, Intent intent) { if (REQUEST_SCAN == reqCode) { if (RESULT_OK == resCode) { String contents = intent.getStringExtra("SCAN_RESULT"); Toast.makeText(this, "Succès : " + contents, 2000).show(); } else if (RESULT_CANCELED == resCode) { Toast.makeText(this, "Scan annulé", 2000).show(); } } }` ". I feel disappointed, frustrated and sad. I still have errors after importing the project. I tried both versions 1.5 and 1.6 zxing I tried to import the project c: \ ZXing-1.6 \ android, and an other new project with c: \ ZXing-1.6 \ zxing-1.6 \ android,I cheked out SVN: ttp: / / zxing.googlecode.com / svn / trunk / zxing-read-only with tortoiseSVN and reproduce the same work, but unfortunately without results! I really fed up with myself ... Please help me to solve this problem.how can I import the project and compile it correctly in my own project? 1 - I use Windows 7 64-bit Home Premium 2 - Eclipse IDE for Java EE Web Developers. Version: Helios Service Release 2 Build id: 20110218-0911 What is the effective and sure method to run this, otherwise if there is a video or a guide details or someone who already done it previously I would really appreciate it if someone would help me out

    Read the article

  • How to save a picture to a file?

    - by Peter vdL
    I'm trying to use a standard Intent that will take a picture, then allow approval or retake. Then I want to save the picture into a file. Here's the Intent I am using: Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); startActivityForResult( intent, 22 ); The docs at http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE say "The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT." I don't pass extra output, I hope to get a Bitmap object in the extra field of the Intent passed into onActivityResult() (for this request). So where/how do you extract it? Intent has a getExtras(), but that returns a Bundle, and Bundle wants a key string to give you something back. What do you invoke on the Intent to extract the bitmap?

    Read the article

  • How to add share menu item to Gallery by code

    - by Anthony
    I know how to implement this issue by Menuifest.xml, see also: Google Android Developer Group related issue But my question is how to add share menu of Gallery by java code not Menuifest.xml. My code is as below: public class MyActivity extends Activity { private static final String TAG = "MyActivity"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_SEND); intentFilter.addCategory(Intent.CATEGORY_DEFAULT); try { intentFilter.addDataType("image/*"); } catch (MalformedMimeTypeException e) { Log.e(TAG, e.toString()); } Intent x = registerReceiver(new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received intent "+intent); intent.setComponent(new ComponentName(context, Uploader.class)); startActivity(intent); } }, intentFilter); if (x==null) Log.i(TAG, "failed to regist a receiver"); else Log.i(TAG, "registed a receiver successfully"); // ... But registerReceiver always return null, and there is no menu added to Gallery's Share. Thank you. Anthony Xu

    Read the article

  • App will not launch from drawer after phone is removed from car dock

    - by BigFwoosh
    I am creating a replacement Car Home app for Android 2.0+ devices. The app needs to launch when the phone is inserted into the car dock, as well as terminate when it is removed from the dock. It also needs to be able to be launched from the app drawer. I'm having a problem right now where once the phone is inserted and removed from the dock, I can no longer launch the app from the app drawer because every time I launch the app my BroadcastReceiver picks up a DOCK_EVENT action for some reason. I created a test project that only registers my BroadcastReceiver, and the same thing happens. Here's the code for the BroadcastReceiver: public class CarDockBroadcastReceiver extends BroadcastReceiver { /** * @see android.content.BroadcastReceiver#onReceive(Context,Intent) */ @Override public void onReceive(Context context, Intent intent) { // TODO Put your code here if(intent.getExtras().containsKey("android.intent.extra.DOCK_STATE")){ int state = intent.getExtras().getInt("android.intent.extra.DOCK_STATE",1); if(state == 0){ Log.i("Dock", "Removed from dock!"); ((Activity)context).finish(); } } } } My main Activity is as follows: public class MainActivity extends Activity { /** Called when the activity is first created. */ CarDockBroadcastReceiver receiver; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); IntentFilter filter = new IntentFilter("android.intent.action.DOCK_EVENT"); receiver = new CarDockBroadcastReceiver(); registerReceiver(receiver, filter); } @Override protected void onDestroy() { // TODO Auto-generated method stub unregisterReceiver(receiver); super.onDestroy(); } } The main Activity has an intent filter for action.MAIN, category.LAUNCHER, category.DEFAULT, and category.CAR_DOCK. Any ideas on why this is happening?

    Read the article

  • Issue in setting alarm time in AlarmManager Class

    - by Anshuman
    I have used the following code in setting alarm time in AlarmManager class. Now Suppose my device current date 9-july-2012 11:31:00, Now suppose i set set a alarm at 9-july-2012 11:45:00, then it works fine and pop-up an alarm at that time. But if i set an alarm at 10-aug-2012 11:40:00, then as soon as exit the app the alarm pop-up, which is wrong because i set an alarm at month of august, So why this happen, is anything wrong in my code. if anyone knows help me to solve this out. Code For Setting Alarm time in AlarmManager class Intent myIntent = new Intent(context, AlarmService.class); PendingIntent pendingIntent = PendingIntent.getService(context, i, myIntent, i); AlarmManager alarmManager = (AlarmManager)context.getSystemService(AlarmService.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.MILLISECOND, (int) dateDifferenceFromSystemTime(NoteManager.getSingletonObject().getAlarmTime(i))); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); public static long dateDifferenceFromSystemTime(Date date) { long difference = 0; try { Calendar c = Calendar.getInstance(); difference = date.getTime() - c.getTimeInMillis(); if (difference < 0) { // if difference is -1 - means alarm time is of previous time then current // then firstly change it to +positive and subtract form 86400000 to get exact new time to play alarm // 86400000-Total no of milliseconds of 24hr Day difference = difference * -1; difference = 86400000 - difference; } } catch (Exception e) { e.printStackTrace(); } return difference; } Service class which pop-up alarm when matches time public class AlarmService extends IntentService { public void onCreate() { super.onCreate(); } public AlarmService() { super("MyAlarmService"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, startId, startId); return START_STICKY; } @Override protected void onHandleIntent(Intent intent) { startActivity(new Intent(this,AlarmDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }

    Read the article

  • emulator browser not connecting to internet

    - by vnshetty
    my emulator browser not connecting to internet? how to do the settings? <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".reader" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> </manifest>

    Read the article

  • How to accept an incoming call by clicking a button?

    - by upright
    HI, all! I'm trying to implement my own phone call handling UI. What I want to do is, if a call comes in, the incoming telephone number and a picture are displayed, and, if I press a button, the incoming call will be accepted/answered. The related codes are: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); answerButton = (Button) findViewById(R.id.pickup); answerButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { Intent intent = new Intent("android.intent.action.ANSWER"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); Sadly, the code does not work. At first, an exception is thrown if I press my answer button: ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.ANSWER Then I added an entry in the AndroidManifest.xml: I run the app again, there is no exception anymore. However, I doubt the incoming call is not really accepted. Because if the press the Android's screen answer button (green button), the incoming call is accepted and a green button is also displayed on the upper left corner of the emulator screen, while my app doesn't. I also read the Phone app's source code in android source. There is method such as acceptCall() in the Phone class. But these codes seem difficult for me to use, because there are many imports declaration in the code, such as : import com.android.internal.telephony.Call; import com.android.internal.telephony.CallStateException; import com.android.internal.telephony.CallerInfo; import com.android.internal.telephony.CallerInfoAsyncQuery; import com.android.internal.telephony.Connection; import com.android.internal.telephony.MmiCode; import com.android.internal.telephony.Phone; And, if I add these imports in my code, there will be too many errors, such as : "The import com.android.internal.telephony cannot be resolved" What is the right and simple way for my problem? Thanks in advance!

    Read the article

  • android widget unresponsive

    - by John
    I have a widget that you press and it then it will update the text on the widget. I have set an on click listener to launch another activity to perform the text update, But for some reason it only works temporarily and then it will become unresponsive and not do anything when pressed. Does anyone know why it might be doing that? i have posted my widget code below in case it is helpful. @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) { thisWidget = new ComponentName(context, MemWidget.class); Intent intent = new Intent(context, updatewidget.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); views.setOnClickPendingIntent(R.id.ImageButton01, pendingIntent); // Tell the AppWidgetManager to perform an update on the current App Widget appWidgetManager.updateAppWidget(thisWidget, views); } @Override public void onReceive(Context context, Intent intent) { appWidgetManager = AppWidgetManager.getInstance(context); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); thisWidget = new ComponentName(context, MemWidget.class); // v1.5 fix that doesn't call onDelete Action final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else { super.onReceive(context, intent); } }

    Read the article

  • ListView setOnItemClickListener in ListFragment not working

    - by Siddarth Kaki
    I am developing an app that uses ActionBar tabs to display a list of options through ListFragment. The list (and ListFragment) display without a problem, but the ListView's setOnItemClickListener doesn't seems to work, as nothing happens when an item in the list is clicked. Here's the code for the ListFragment class: package XXX.XXX; public class AboutFrag extends SherlockListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.aboutfrag, container, false); ListView lv = (ListView) view.findViewById(android.R.id.list); String[] items = new String[] {"About 1", "About 2", "About 3"}; lv.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.list_item, items)); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com")); startActivityForResult(browserIntent, 0); break; case 1: Intent browserIntent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://wikipedia.org")); startActivityForResult(browserIntent2, 0); break; case 2: Intent browserIntent3 = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/android.com"); startActivityForResult(browserIntent3, 0); break; } } }); return view; } } I'm assuming it does not work because the class returns the view object, so the FragmentActivity can't run the listener code, so does anyone know how to make this work? By the way, I am using ActionBarSherlock. Thanks in advance!!!

    Read the article

  • using IntentExatras with Alarm Manager

    - by Ashwin
    I want to know if this code will work(I cannot try it out right now. Moreover, I have a few doubts that have to be cleared). Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra("user",global.getUsername()); intent.puExtra("password",global.getPassword); PendingIntent sender = PendingIntent.getBroadcast(context, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Get the AlarmManager service Log.v("inside log_run", "new service started"); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, IMMEDIATELY,60000,sender); finish(); As you can see, this code starts an AlarmManager with setRepeating(). If you see the intent(actually the pending intent) passed on to the BroadcastReceiver, there are two extras that are passed on. These are global variables that live as long as the Application is running. But this AlarmManager is meant to be run in the background (that is application will be alive only for the first few calls of the o fthe alrmamanager to the broadcast recevier) My Question Will AlarmManager make a copy of the global variables(the username and password) and maintain this copy to be passed along with the intent? Because, these values will be used in the broadcast receiver.

    Read the article

  • How to launch android email setup screen programmatically from my activity

    - by ganesh
    hi, I could send mail from my Activity when i have already configured with any email account in android ,but in case if have not configured ,is there any way to launch email setup screen from my Activity ,or at least check whether email account is setup before sending a email. If i haven't set up my email account then the following code takes me to compose SMS/MMS,which i don't want ,Please give your suggestion. Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL, "xxx.com"); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "..."); emailIntent.putExtra(Intent.EXTRA_TEXT,"..."); emailIntent.setType("text/plain"); startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    Read the article

  • Startup Broadcast Receiver Not Running At Startup

    - by comead
    I have a class StartupReceiver: public class StartupReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent service = new Intent(context, ARMRService.class); context.startService(service); } and it is declared in my Manifest.xml as <receiver android:name=".StartupReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> and I have given the correct permission: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> Why is this not working???

    Read the article

  • My app has some basic problems, and it stops working

    - by user2882662
    I am writing a basic application which contains two activities. Both contain a TextView showing the title and the first one contains an EditText in which the user types a message and clicks on a button on its side, the second activity is launched which shows the message the user types. It has the following problems: The title (the first TextView in both the activities) doesn't show in the middle of the line, despite of the android:gravity="center_horizontal" attribute. The EditText in the first activity does not show at all. When I click on the button, the app stops saying "Unfortunately Write n Display and stopped.", rather than launching the second activity at all. I don't have adequate knowledge about logcat, but I have followed the steps somebody had told me, that is WindowOpen Perspective Other DDMS Then run the app and select the package name from the Devices and click on log cat, select the exception(s) and export to text file. All contained in the text file is : : E/(): Device disconnected: 1 Since I am not sure of using log cat, so I am posting a screenshot to make clear what I have done. CODE OF FIRST ACTIVITY: - package com.practice.myfirstapp1; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; //import android.view.Menu; public class MainActivity extends Activity { public static final String key_name="com.practice.firstApp.key"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } private void sendMessage(View view){ Intent intent= new Intent(this, SecondActivity.class); EditText editText=(EditText) findViewById(R.id.EditText1_MainActivity); String key_value= editText.getText().toString(); intent.putExtra(key_name, key_value); startActivity(intent); } } LAYOUT OF FIRST ACTIVITY: - <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/TextView1_MainActivity" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+string/title_MainActivity" android:gravity="center_horizontal" android:textStyle="bold"/> <EditText android:id="@+id/EditText1_MainActivity" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_below="@+id/TextView1_MainActivity" android:hint="@string/EditText_MainActivity" android:textStyle="italic" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/TextView1_MainActivity" android:layout_toRightOf="@id/EditText1_MainActivity" android:text="@string/Button_MainActivity" android:onClick="sendMessage"/> </RelativeLayout> CODE OF SECOND ACTIVITY: - package com.practice.myfirstapp1; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Intent intent= getIntent(); String intent_value= intent.getStringExtra(MainActivity.key_name); TextView textView= new TextView(this); textView= (TextView) findViewById(R.id.TextView2_SecondActivity); textView.setText(intent_value); } } LAYOUT OF SECOND ACTIVITY: - <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".SecondActivity"> <TextView android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+string/title_SecondActivity" android:gravity="center_horizontal" android:textStyle="bold"/> <TextView android:id="@+id/TextView2_SecondActivity" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> STRINGS RESOURCE FILE:- <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Write n Display</string> <string name="action_settings">Settings</string> <string name="title_MainActivity">WRITE</string> <string name="EditText_MainActivity">Your Message here</string> <string name="Button_MainActivity">Send</string> <string name="title_SecondActivity">DISPLAY</string> </resources> ANDROID MANIFEST FILE: - <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.practice.myfirstapp1" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <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.practice.myfirstapp1.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.practive.myfirstapp1.SecondActivity" android:label="@string/app_name"> </activity> </application> </manifest>

    Read the article

  • How to have onSearchRequested not open a web browser.

    - by pcm2a
    I have a button in my app. When it is pressed I call the onSearchRequested() method. When this is called the stock search box comes up so the user can type some junk in there. When they press "Go" I need the results returned back to my application but instead the stock browser is opened and a google search is performed. How can I tell it to return the results to my application instead. I've tried these items in my manifest.xml file: <meta-data android:name="android.app.default_searchable" android:value=".MainActivity" /> <activity android:name=".MainActivity" android:launchMode="singleTop" <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> I've also tried to capture the result in my onCreate with this: Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction()))

    Read the article

  • Updating Android Home Screen TextView

    - by jmontex2
    Hi, How can we update the View of a Home Screen Widget on the onReceive method of AppWidgetProvider?. I am trying to update the TextView of my Home screen widget but it seems that I cant access the TextView of my AppWidgetProvider on onReceive method. Here is a sample code of my onReceive public void onReceive(Context context,Intent intent) { final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else { if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { String msg = "null"; try { msg = intent.getStringExtra("msg"); } catch (NullPointerException e) { } Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); // code for gathering the text to update the TextView } } super.onReceive(context, intent); }

    Read the article

  • ACTION_MY_PACKAGE_REPLACED not received

    - by Ton
    I am using ACTION_MY_PACKAGE_REPLACED to receive when my app is updated or resinstalled. My problem is that the event is never triggered (I tried Eclipse and real device). This is what I do: Manifest: <receiver android:name=".MyEventReceiver" > <intent-filter android:priority="1000" > <action android:name="android.intent.action.ACTION_MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> Code: public class MyEventReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if ("android.intent.action.ACTION_MY_PACKAGE_REPLACED".equals(intent.getAction())) { //Restart services } } } This code is simple, in real one I used other events like BOOT_COMPLETED and others, and they work but ACTION_MY_PACKAGE_REPLACED. Thanks.

    Read the article

  • How to send html content in the Email body

    - by Shalini Singh
    Hi, i am using android code with html tag.. but in mail getting same html tag please help me how can i send html link ... the code is giving below Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/html"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[EMAIL PROTECTED]"}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example"); context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    Read the article

  • Show Alertdialog and use vibrator

    - by user1007522
    I'm having a class that implements RecognitionListener like this: public class listener implements RecognitionListener I wanted to show a alertdialog and use the vibrator but this isn't possible because I need to provide a context what I don't have. My alertdialog code was like this: new AlertDialog.Builder(this) .setTitle("dd") .setMessage("aa") .setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .show(); But the AlertDialog.Builder(this) wants a context, the same problem with my vibrator code: v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); The getSystemService method isn't available. My code that starts the class: sr = SpeechRecognizer.createSpeechRecognizer(this); sr.setRecognitionListener(new listener()); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); sr.startListening(intent); Whats the best way to solve this?

    Read the article

  • Android 1.6: onActivityResult is not called

    - by Seb
    Hi, I have a problem with the method "onActivityResult". I create a new Activity from my main activity: Intent intent = new Intent(this, NewActivity.class); startActivityForResult(intent, 0); The new Activity is ended like this: Intent resultIntent = new Intent(); resultIntent.putExtra("vid", hmvenues.get(venues[currentPosition])); resultIntent.putExtra("name", venues[currentPosition]); setResult(RESULT_OK, resultIntent); finish(); But the Method onActivityResult seem to be not called @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(this.getClass().getName(),"onActivityResult"); ... } Does anyone have an idea, what I did wrong? Thanks!! Seb

    Read the article

  • How to remove icon programatically (Android)

    - by user1865039
    By remove the below intent-filter in AndroidManifest.xml, it can remove the icon after install. <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> But i have try the below when on Boot than remove the Icon, but the icon still remain after reboot. I have add the permission, and this reboot receiver is work. public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { PackageManager p = context.getApplicationContext().getPackageManager(); ComponentName componentName = new ComponentName("com.example.remove_icon","com.example.remove_icon.LauncherActivity"); p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }

    Read the article

  • Android Augmented Reality

    - by Azooz Totti
    I'm working on my first Android Augmented Reality application. The application works pretty good if the ARActivity runs as the first class (android.intent.category.LAUNCHER) in the manifest file. But when I added a splash screen which means the ARActivity will be the second to run(android.intent.category.DEFAULT), the camera seems not detecting the marker. I believe the problem is all in the manifest file. Any suggestions ? Thanks This is the manifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ar.armarkers" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".Splash" android:screenOrientation="landscape" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.ar.armarkers.MainActivity" android:clearTaskOnLaunch="true" android:label="@string/title_activity_main" android:noHistory="true" android:screenOrientation="landscape" > <intent-filter> <action android:name="com.ar.armarkers.MAINACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest> MainActivity.java import edu.dhbw.andar.ARObject; import edu.dhbw.andar.ARToolkit; import edu.dhbw.andar.AndARActivity; import edu.dhbw.andar.exceptions.AndARException; import edu.dhbw.andar.pub.CustomRenderer; import android.os.Bundle; import android.util.Log; public class MainActivity extends AndARActivity { private ARObject someObject; private ARToolkit artoolkit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CustomRenderer renderer = new CustomRenderer(); setNonARRenderer(renderer); try { artoolkit = getArtoolkit(); someObject = new CustomObject1("test", "marker16.pat", 80.0, new double[] { 0, 0 }); artoolkit.registerARObject(someObject); someObject = new CustomObject2 ("test", "marker17.patt", 80.0, new double[]{0,0}); artoolkit.registerARObject(someObject); } catch (AndARException ex) { System.out.println(""); } startPreview(); } public void uncaughtException(Thread thread, Throwable ex) { // TODO Auto-generated method stub Log.e("AndAR EXCEPTION", ex.getMessage()); finish(); } } Splash.java import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.view.Gravity; public class Splash extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.splash); Thread timer = new Thread() { public void run() { try { sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } finally { Intent i = new Intent(getApplicationContext(), MainActivity.class); startActivity(i); } } }; timer.start(); } }

    Read the article

  • How to set icon to title bar for each Activity in Tablelayout in android

    - by Venu Gopal
    In my tablayout example, i have created 3 tabs, as usually i set 3 activities for each tab. I can set image to title bar of activity, which adds the intent to each tab. Due to this, the image in the title bar is visible in all 3 tabs. My requirement is to set a different image to title bar for each activity. I followed this to set image to title bar. But when i am going to do the same thing to each activity, getting android.util.AndroidRuntimeException: You cannot combine custom titles with other title features this error and application is terminated. manifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.aptitsolution.tablayout" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/MyTheme"> <activity android:name=".TabLayoutDemo" 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="AlbumsActivity"></activity> <activity android:name="ArtistsActivity"></activity> <activity android:name="SongsActivity"></activity> TabLayoutDemo.java public class TabLayoutDemo extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); .... .... ArtistsActivity.java public class ArtistsActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//here i am getting the error setContentView(R.layout.artists); setFeatureDrawableResource(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title); } } my_title.xml <?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/header" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent"> <ImageView android:id="@+id/titleImage" android:src="@drawable/nowplaying" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/titleText" android:layout_toRightOf="id/titleImage"android:layout_width="wrap_content" android:text="New Title" android:layout_height="wrap_content"/> thanks venu

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >