Opening android deep links from app - android

I am implementing deep links inside my app and could not find a way, or example about opening them from inside my own app. For example: I wish that opening certain banner would open myapp://game/1 link which would lead to another activity inside my app. How can I do that ?

In the manifest you should register the deep linking scheme.
<activity android:name=".DeepLinkingActivity"
android:configChanges="orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myapp" />
</intent-filter>
</activity>
With this the DeepLinkingActivity will open when the the link with the defined scheme is clicked. And in the activity handle what to do:
private final String GAME_LINK = "game";
private final String VIDEO_LINK = "video";
private static String PASSED_LINK = "PassedLink";
public static Intent createIntent(String link, Context context) {
Intent intent = new Intent(context, DeepLinkingActivity.class);
intent.putExtra(PASSED_LINK, link);
return intent;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
String host;
String link = getIntent().getStringExtra(PASSED_LINK);
if(TextUtils.isEmpty(link)) {
Intent intent = getIntent();
if (intent.getData() != null) {
Uri data = intent.getData();
host = data.getHost();
} else {
// No links
}
} else {
Uri data = Uri.parse(link);
host = data.getHost();
}
if(host.equals(GAME_LINK)) {
// myapp://game/
// Do something
} else if(host.equals(VIDEO_LINK)){
// myapp://video/
// Do something
} else {
// Do something
}
...
}
Then you can call from your widget:
widget.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(DeepLinkingActivity.createIntent("linik_for_this_wiget"), getContext());
}
});
If you have links in WebView you could also override shouldOverrideUrlLoading

Related

Receive Images from another app to our app

So when I am in other media apps like google photos I select an image and click the share button then in the share window I want my app to be displayed so that i can click it and get that image to my app.
I have build a simple chat application where users can send text and images to each other where all the data is stored in Firebase.
So when one clicks my app in the sharing screen the image should take me to the Chat activity where i have all my chats so that i click one of my chats and the image is then sent to them.
So how to achieve this process?I have searched everywhere and couldn't get the hang of the right tutorial all i am finding is sharing data from our app and not from other app to our app.
Thank you.
Edit : I have created a separate activity that should be launched when a user choses to share a image from other app.But when i click my app in the sharing menu then my app goes all white screen instead of launching the SharingActivity.
Below is my code and manifest file.
SharingActivity.java
package com.pappu5.navigation;
public class SharingActivity extends AppCompatActivity {
FirebaseRecyclerAdapter<FriendsData, SharingActivity.ShareHolder> frv;
private RecyclerView rv;
private DatabaseReference dr, drUsers;
private FirebaseAuth auth;
private String user;
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
rv = (RecyclerView) findViewById(R.id.friendsView);
auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser().getUid();
dr = FirebaseDatabase.getInstance().getReference().child("Friends_Formed").child(user);
drUsers = FirebaseDatabase.getInstance().getReference().child("Chat_Profiles");
dr.keepSynced(true);
drUsers.keepSynced(true);
rv.setHasFixedSize(true);
rv.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
Query personsQuery = dr.orderByKey();
FirebaseRecyclerOptions<FriendsData> options =
new FirebaseRecyclerOptions.Builder<FriendsData>().setLifecycleOwner(this)
.setQuery(personsQuery, FriendsData.class)
.build();
frv = new FirebaseRecyclerAdapter<FriendsData, SharingActivity.ShareHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull final SharingActivity.ShareHolder holder, int position, #NonNull FriendsData model) {
holder.setDate(model.getDate());
holder.setImage(model.getThumb_image());
final String listUsers = getRef(position).getKey();
if (!listUsers.equals(null))
drUsers.child(listUsers).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
final String username = dataSnapshot.child("name").getValue().toString();
String thumb = dataSnapshot.child("thumb_image").getValue().toString();
//String online = dataSnapshot.child("onlineStatus").getValue().toString();
if (dataSnapshot.hasChild("onlineStatus")) {
String userOnline = dataSnapshot.child("onlineStatus").getValue().toString();
holder.setOnlineStatus(userOnline);
}
holder.setName(username);
holder.setImage(thumb);
//holder.setOnlineStatus(online);
holder.view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CharSequence[] actions = new CharSequence[]{"Share to " + username};
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Select an Action");
builder.setItems(actions, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
intent.putExtra("id", listUsers);
intent.putExtra("user_name", username);
startActivity(intent);
}
}
});
builder.show();
}
});
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
#NonNull
#Override
public SharingActivity.ShareHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.friends_status, parent, false);
return new SharingActivity.ShareHolder(view);
}
};
rv.setAdapter(frv);
}
public static class ShareHolder extends RecyclerView.ViewHolder {
View view;
public ShareHolder(View itemView) {
super(itemView);
view = itemView;
}
public void setDate(String date) {
TextView username = (TextView) view.findViewById(R.id.status2);
username.setText(date);
}
public void setImage(String image) {
CircleImageView thumb = (CircleImageView) view.findViewById(R.id.circleImageView2);
Picasso.get().load(image).placeholder(R.drawable.default_avatar).into(thumb);
}
public void setName(String name) {
TextView username = (TextView) view.findViewById(R.id.name2);
username.setText(name);
}
public void setOnlineStatus(String onlineStatus) {
ImageView image = (ImageView) view.findViewById(R.id.onlineStatus);
if (onlineStatus.equals("true")) {
image.setVisibility(View.VISIBLE);
} else {
image.setVisibility(View.INVISIBLE);
}
}
}
}
AndroidManifest.xml
<activity android:name=".SharingActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
You have to add below code inside Manifest.xml under activity tag like
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:noHistory="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
// below code with show your app as sharing option
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
You can change mimeType according to your need.
Hope this will help you.

quick tiles is shown but not active in notification bar

I am trying to implement simple quick settings tile with the help of google docs,
but my tile appears to be there but greyed out(intent activity)- I can't click or do anything with it and cant remove it either without restarting my phone(one plus 3T/oreo8.0.0).
and the same thing goes with sample code google provided.
what things do i need to keep in mind/ how to do it?
is there anything I am missing?
I saw one similar question but it was a bit over my head.
MANIFEST
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".QSIntentService"
android:icon="#drawable/ic_android_black_24dp"
android:label="#string/qs_intent_tile_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<activity
android:name=".ResultActivity"
android:label="#string/result_label"/>
</application>
JAVA (Main ACtivity)
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
QSintentservice.java
public class QSIntentService extends TileService{
private static final String SERVICE_STATUS_FLAG = "serviceStatus";
private static final String PREFERENCES_KEY = "com.google.android_quick_settings";
#Override
public void onClick() {
updateTile();
boolean isCurrentlyLocked = this.isLocked();
if (!isCurrentlyLocked) {
Resources resources = getApplication().getResources();
Tile tile = getQsTile();
String tileLabel = tile.getLabel().toString();
String tileState = (tile.getState() == Tile.STATE_ACTIVE) ?
resources.getString(R.string.service_active) :
resources.getString(R.string.service_inactive);
Intent intent = new Intent(getApplicationContext(),
ResultActivity.class);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_NAME_KEY,
tileLabel);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_INFO_KEY,
tileState);
startActivityAndCollapse(intent);
}
}
private void updateTile() {
Tile tile = this.getQsTile();
boolean isActive = getServiceStatus();
Icon newIcon;
String newLabel;
int newState;
if (isActive) {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_active));
newIcon = Icon.createWithResource(getApplicationContext(), ic_android_black_24dp);
newState = Tile.STATE_ACTIVE;
} else {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_inactive));
newIcon =
Icon.createWithResource(getApplicationContext(),
android.R.drawable.ic_dialog_alert);
newState = Tile.STATE_INACTIVE;
}
tile.setLabel(newLabel);
tile.setIcon(newIcon);
tile.setState(newState);
tile.updateTile();
}
private boolean getServiceStatus() {
SharedPreferences prefs =
getApplicationContext()
.getSharedPreferences(PREFERENCES_KEY,
MODE_PRIVATE);
boolean isActive = prefs.getBoolean(SERVICE_STATUS_FLAG, false);
isActive = !isActive;
prefs.edit().putBoolean(SERVICE_STATUS_FLAG, isActive).apply();
return isActive;
}
}
Result.java
public class ResultActivity extends AppCompatActivity {
public static final String RESULT_ACTIVITY_INFO_KEY = "resultActivityInfo";
public static final String RESULT_ACTIVITY_NAME_KEY = "resultActivityName";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
assert extras != null;
String tileState = extras.getString(RESULT_ACTIVITY_INFO_KEY);
String tileName = extras.getString(RESULT_ACTIVITY_NAME_KEY);
TextView outputText = findViewById(R.id.result_info);
outputText.setText(String.format(Locale.US,
getString(R.string.result_output),
tileName,
tileState));
TextView returnHome = findViewById(R.id.result_return_main);
returnHome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent goHome = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(goHome);
}
});
}
}
}
This code works fine on other devices. However, there is an issue in one plus quick setting menu as its observed and brought to notice. Check the below link to verify,
https://forums.oneplus.net/threads/android-oreo-8-0-oxigenos-quick-settings-bug.690621/

callback url not returning to the android screen

Linkedin authorization callback url not returning to the android screen. Below is the code which i have tried:
String linkedinKey = "xxxxx"; //add your LinkedIn key
String linkedinSecret = "xxxx"; //add your LinkedIn Secret
public static final String OAUTH_CALLBACK_SCHEME = "callback";
public static final String OAUTH_CALLBACK_URL = "x-oauthflow-linkedin" + ":///"+ "callback";
LinkedInRequestToken LinkedinrequestToken ;
Intent i;
final LinkedInOAuthService oauthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(linkedinKey,linkedinSecret);
final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(linkedinKey,linkedinSecret);
LinkedInApiClient client;
ImageView btnLinkedInLogin=(ImageView)findViewById(R.id.btnLinkedInLogin);
btnLinkedInLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinkedinrequestToken = oauthService.getOAuthRequestToken(OAUTH_CALLBACK_URL);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(LinkedinrequestToken.getAuthorizationUrl()));
// i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
}
});
private void OnNewIntent()
{
Log.d("newintent","hi");
String verifier = i.getData().getQueryParameter("oauth_verifier");
LinkedInAccessToken accessToken = oauthService.getOAuthAccessToken(LinkedinrequestToken, verifier);
Log.d("token",accessToken.toString());
}
Manifest.xml
<activity
android:name=".Login"
android:launchMode="singleTop"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/AppThemes" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="t4jsample"
android:scheme="oauth" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="x-oauth-linkedin" android:host="callback" />
</intent-filter>
</activity>
But my webpage stops at authorization successful. It doesn't return to the android screen.
My OnNewIntent() function is not called.
As I can see, You have used onNewIntent in wrong way, just use like this:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("newintent","hi");
String verifier = i.getData().getQueryParameter("oauth_verifier");
LinkedInAccessToken accessToken = oauthService.getOAuthAccessToken(LinkedinrequestToken, verifier);
Log.d("token",accessToken.toString());
}
You can invoke onNewIntent always by putting it into onCreate method like below, so make sure if you did like this:
#Override
public void onCreate(Bundle savedState)
{
super.onCreate(savedState);
onNewIntent(getIntent());
}
Hope this will help. Thanks. :)

Read NFC tags and back button

My problem is related to the back button and the backstack, ive got a app for reading nfc tags, so ive launch Activity A, then go for Activity B, that is declared SingleTop in the manifest.
I aproach the phone to the tags and it reads the tag, everything is working fine at this moment.
If i press the back button , it goes back to activity B,instead of going to the Activity A, and then if i pressed the backbutton again it goes to Activity A.
Like this:
A->B->read Tags->B->press back button ->B->press back button ->A->press back button ->close app.
and i want like this:
A->B->read Tags->B->press back button-> A->press back button ->close app.
I want only one instance of B.
I have tried single task , but the problem is i ve click in the app icon, and the activity b is launched, but the intent from reading tags is preserved.
public class B extends Activity {
private static final String KINVEY_KEY = YOUR_APP_KEY;
private static final String KINVEY_SECRET_KEY = 'YOUR_APP_SECRET_KEY';
private KCSClient kinveyClient;
private NfcAdapter mNfcAdapter;
private Button mEnableWriteButton;
private EditText mTextField;
private ProgressBar mProgressBar;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tags);
mTextField = (EditText) findViewById(R.id.text_field);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
mProgressBar.setVisibility(View.GONE);
mEnableWriteButton = (Button) findViewById(R.id.enable_write_button);
mEnableWriteButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
setTagWriteReady(!isWriteReady);
mProgressBar.setVisibility(isWriteReady ? View.VISIBLE : View.GONE);
}
});
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null) {
Toast.makeText(this, 'Sorry, NFC is not available on this device', Toast.LENGTH_SHORT).show();
finish();
}
// Initialize Kinvey
KinveySettings settings = new KinveySettings(KINVEY_KEY, KINVEY_SECRET_KEY);
kinveyClient = KCSClient.getInstance(this.getApplicationContext(), settings);
}
private boolean isWriteReady = false;
public void setTagWriteReady(boolean isWriteReady) {
this.isWriteReady = isWriteReady;
if (isWriteReady) {
IntentFilter[] writeTagFilters = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) };
mNfcAdapter.enableForegroundDispatch(TagsActivity.this, NfcUtils.getPendingIntent(TagsActivity.this),
writeTagFilters, null);
} else {
// Disable dispatch if not writing tags
mNfcAdapter.disableForegroundDispatch(TagsActivity.this);
}
mProgressBar.setVisibility(isWriteReady ? View.VISIBLE : View.GONE);
}
#Override
public void onNewIntent(Intent intent) {
// onResume gets called after this to handle the intent
setIntent(intent);
}
#Override
public void onResume() {
super.onResume();
if (isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())) {
processWriteIntent(getIntent());
} else if (!isWriteReady
&& (NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction()) || NfcAdapter.ACTION_NDEF_DISCOVERED
.equals(getIntent().getAction()))) {
processReadIntent(getIntent());
}
}
private static final String MIME_TYPE = 'application/com.tapped.nfc.tag';
public void processWriteIntent(Intent intent) {
if (isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())) {
Tag detectedTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
String tagWriteMessage = mTextField.getText().toString();
byte[] payload = new String(tagWriteMessage).getBytes();
if (detectedTag != null && NfcUtils.writeTag(
NfcUtils.createMessage(MIME_TYPE, payload), detectedTag)) {
Toast.makeText(this, "Wrote '" + tagWriteMessage + "' to a tag!",
Toast.LENGTH_LONG).show();
setTagWriteReady(false);
} else {
Toast.makeText(this, "Write failed. Please try again.", Toast.LENGTH_LONG).show();
}
}
}
public void processReadIntent(Intent intent) {
List<NdefMessage> intentMessages = NfcUtils.getMessagesFromIntent(intent);
List<String> payloadStrings = new ArrayList<String>(intentMessages.size());
for (NdefMessage message : intentMessages) {
for (NdefRecord record : message.getRecords()) {
byte[] payload = record.getPayload();
String payloadString = new String(payload);
if (!TextUtils.isEmpty(payloadString))
payloadStrings.add(payloadString);
}
}
if (!payloadStrings.isEmpty()) {
String content = TextUtils.join(",", payloadStrings);
Toast.makeText(TagsActivity.this, "Read from tag: " + content,
Toast.LENGTH_LONG).show();
saveTag(content);
}
}
private void saveTag(String tagMessage){
TagReadEntity tag = new TagReadEntity(UUID.randomUUID().toString(),
tagMessage, System.currentTimeMillis());
kinveyClient.mappeddata("tags").save(tag, new ScalarCallback<TagReadEntity>() {
#Override
public void onSuccess(TagReadEntity tag) {
Log.i("NFC Demo", "Saved tag!");
}
#Override
public void onFailure(Throwable e) {
Log.e("NFC Demo", "Error saving tag", e);
}
});
}
}
and the manifest:
<activity
android:name=".TagsActivity"
android:label="#string/title_activity_tags"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.tapped.nfc.tag" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.tapped.nfc.tag" />
</intent-filter>
</activity>
ive declared the task as singletask, it seems to work now.
android:launchMode="singleTask"
ive tried standart, and everytime ive read a nfc tags, a new activity was created, if a read 10 tags, i need ti press the back button 9times.
after ive tried singleTop, and now i was going from A to B, then no matter how many times i read the tags there was only 2 instances of B, so i need to press back once to go to activity B, and back again to close the app.

Android: Twitter in WebView - Back to an Activity by callback

I try to create Twitter client and now I deal with authorization via OAuth protocol. I have created "Sign In" button to come in WebView and load twitter authorization URL, that's work. However, when the authorization is accepted successfuly and Twitter service redirect me to my callback I receive error web page in WebView. That is to say I am not redirected to my activity, I still stay in WebView. But if try the same way via browser, it`s working. What the problem is that?
Main Activivty:
public class Twitter extends Activity implements OnClickListener {
Button bSignIn;
TextView status;
private OAuthConsumer consumer;
private OAuthProvider provider;
private String url;
final String TAG = getClass().getName();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
bSignIn = (Button) findViewById(R.id.bSignIn);
status = (TextView) findViewById(R.id.tvStatus);
bSignIn.setOnClickListener(this);
}
public void onClick(View v) {
new OAuthWebViewProcess().execute();
}
public class OAuthWebViewProcess extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog;
protected void onPreExecute() {
dialog = ProgressDialog.show(Twitter.this, null,
"Connecting, please wait...");
}
protected Void doInBackground(Void... params) {
try {
consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider(Constants.REQUEST_URL,
Constants.ACCESS_URL, Constants.AUTHORIZE_URL);
url = provider.retrieveRequestToken(consumer,
Constants.OAUTH_CALLBACK_URL);
} catch (Exception e) {
Log.e(TAG, "Error during OAUth retrieve request token", e);
}
return null;
}
protected void onPostExecute(Void result) {
//Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Intent i = new Intent(Twitter.this, TwitterWebView.class);
i.putExtra("url", Uri.parse(url).toString());
startActivityForResult(i, 1);
dialog.dismiss();
}
}
}
WebView for Twitter:
public class TwitterWebView extends Activity {
String url;
WebView TwitterWebView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twitterwebview);
Bundle extras = getIntent().getExtras();
url = extras.getString("url");
try {
TwitterWebView = (WebView) findViewById(R.id.wvTwitter);
TwitterWebView.setWebViewClient(new TwitterWebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
TwitterWebView.getSettings().setJavaScriptEnabled(true);
TwitterWebView.getSettings().setDomStorageEnabled(true);
TwitterWebView.getSettings().setSavePassword(false);
TwitterWebView.getSettings().setSaveFormData(false);
TwitterWebView.getSettings().setSupportZoom(false);
TwitterWebView.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wixanz.app.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Twitter"
android:label="#string/app_name"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TwitterWebView"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".TweetList"
android:label="TweetList"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="callback"
android:scheme="twitter" />
</intent-filter>
</activity>
</application>
</manifest>
I did the same about others networks like LinkedIn, Foursquare. But instead of use the callback URL, I override the method shouldOverrideUrlLoading (WebView view, String url) in your WebViewClient (which is used to show the login page) to catch the access token and the token secret (if needed) by myself.

Categories

Resources